"fix - left area "
Bootstrap 4.1.1 Snippet by vivekbisht109

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!-- partial:index.partial.html --> <header></header> <main> <article class="article"> <h2>Dynamic Sticky Sidebar Component</h2> <p>Click on the elements below to add them to the sidebar component.</p> <ul class="items grid"> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> <li> <button class="item"> <div class="thumbnail"></div> <div class="info"> <div class="title"></div> <div class="subtitle"></div> </div> </button> </li> </ul> <p>Added this extra content for spacing purposes. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sed porta arcu, vitae hendrerit magna. Nullam nec mi augue. Morbi non odio mauris. Vivamus accumsan lectus ac libero ornare lacinia. Etiam quis purus nec augue fermentum interdum. Aliquam sit amet dui rutrum, aliquam augue ut, iaculis arcu. Nunc euismod, magna sit amet gravida gravida, erat diam scelerisque massa, id dignissim sapien elit quis mauris. In interdum lectus id mattis aliquam. Ut pellentesque accumsan consectetur. Curabitur varius mollis lacus, nec rhoncus massa facilisis ac.</p> <p>Maecenas fringilla consectetur blandit. Phasellus pulvinar, eros eleifend fermentum accumsan, leo massa rutrum lectus, nec cursus orci turpis at libero. Quisque dolor ex, suscipit id felis ac, bibendum aliquam enim. Curabitur mollis ligula a ipsum fermentum, in volutpat arcu mattis. Nulla facilisi. Duis mattis venenatis erat non sollicitudin. Phasellus nec augue eget magna eleifend laoreet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed bibendum dolor euismod erat rhoncus, et mattis enim facilisis. Quisque arcu est, molestie sed massa nec, gravida feugiat massa. Donec id velit mi. Curabitur accumsan elit in magna mollis, quis pharetra felis faucibus.</p> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In molestie magna sit amet lobortis convallis. Etiam at magna eget risus venenatis luctus quis nec justo. Pellentesque elementum imperdiet mi. Vivamus nec fringilla est. Suspendisse tincidunt euismod turpis quis ornare. Donec et dui in massa porttitor malesuada. Aliquam erat volutpat.</p> </article> <aside class="sidebar"> <div class="component"> <div class="header">Selected Items</div> <div class="content"> <div class="empty-text">Your cart is currently empty</div> <ul class="items list"></ul> </div> <div class="footer"> <button class="button">Checkout</button> <button class="button empty-cart">Empty Cart</button> </div> </div> </aside> </main> <footer></footer> <footer></footer> <footer></footer>
:root { --space: 2rem; --space-xs: calc(var(--space) / 3); --space-sm: calc(var(--space) / 2); --space-md: calc(var(--space) * 2); --color-primary: lightgray; --color-accent: whitesmoke; --color-dark: black; --color-mid: gray; --color-light: white; --color-highlight: dodgerblue; --radius: 0.125rem; } /* Here are the base styles for the main layout and sticky component */ * { box-sizing: border-box; } main { display: flex; flex-wrap: wrap; } .article { flex-basis: 0; flex-grow: 999; min-width: 40%; } .sidebar { --offset: var(--space); flex-grow: 1; flex-basis: 300px; align-self: start; position: sticky; top: var(--offset); } .component { display: grid; grid-template-rows: auto 1fr auto; } .component .content { max-height: 500px; overflow-y: auto; } .sidebar .component { max-height: calc(100vh - var(--offset) * 2); } /* * Other styles **/ .visually-hidden { clip: rect(0 0 0 0); -webkit-clip-path: inset(50%); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; } html, body { height: 100%; } [hidden] { display: none; } body { margin: 0 auto; padding: 0 var(--space); font-family: "Helvetica Neue", sans-serif; font-size: 1.25rem; line-height: 1.4; max-width: 1400px; } h2 { font-size: clamp(2rem, 4vw, 3.5rem); font-weight: 600; line-height: 1.2; } p { max-width: 70ch; font-size: clamp(1rem, 4vw, 1.25rem); } header, footer { display: flex; align-items: center; justify-content: center; margin: var(--space-md) 0; padding: var(--space); height: 40vh; background: repeating-linear-gradient( 45deg, transparent, transparent 12px, var(--color-accent) 12px, var(--color-accent) 24px ); } /* Until flexbox gap is supported in all modern browsers, we use the negative margin trick to create space between the children elements */ main { margin-bottom: calc(var(--space-md) * -1); margin-left: calc(var(--space-md) * -1); } main > * { margin-bottom: var(--space-md); margin-left: var(--space-md); } article > * + * { margin-top: var(--space); } .component { position: relative; border: 1px solid var(--color-primary); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.04), 0 4px 8px rgba(0, 0, 0, 0.03), 0 8px 16px rgba(0, 0, 0, 0.03), 0 16px 32px rgba(0, 0, 0, 0.02), 0 32px 64px rgba(0, 0, 0, 0.02); } .component .header, .component .footer { padding: var(--space-sm); text-align: center; } .component .header { border-bottom: inherit; } .component .footer { display: flex; justify-content: space-between; border-top: inherit; } .component .content { padding: var(--space-sm); max-height: 500px; overflow-y: auto; color: var(--color-dark); } .empty-text { padding: var(--space); text-align: center; color: var(--color-primary); } .item { position: relative; -webkit-appearance: none; -moz-appearance: none; appearance: none; display: flex; align-items: center; padding: var(--space); outline: none; width: 100%; background-color: var(--color-accent); border: 1px solid var(--color-accent); border-radius: var(--radius); cursor: pointer; } .item:active { transform: translateY(1px); } .item:focus { outline: 2px solid var(--color-highlight); } .item > * { pointer-events: none; } .info { width: 100%; } .title, .subtitle { width: 100%; height: 0.5rem; background-color: var(--color-primary); border-radius: var(--radius); } .title { margin-bottom: var(--space-xs); max-width: 15ch; } .subtitle { max-width: 12ch; } .thumbnail { flex-shrink: 0; width: var(--size); height: var(--size); background: var(--color-primary); border-radius: var(--radius); } .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-gap: var(--space-sm); } .grid .item { flex-direction: column; text-align: center; } .grid .info { display: flex; flex-direction: column; align-items: center; } .grid .thumbnail { --size: 100px; margin-bottom: var(--space); } .list > * + * { margin-top: var(--space-xs); } .list .item { padding: var(--space-sm); } .list .item::before { content: "×"; position: absolute; top: 0; right: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: flex-end; padding-right: var(--space-sm); font-size: 2rem; text-align: center; text-transform: uppercase; letter-spacing: 0.05rem; color: var(--color-primary); pointer-events: none; } .list .thumbnail { --size: 50px; margin-right: var(--space-sm); } .button { -webkit-appearance: none; -moz-appearance: none; appearance: none; padding: var(--space-xs) var(--space-sm); font-family: inherit; font-size: 1rem; color: white; background-color: var(--color-dark); border: 1px solid var(--color-dark); cursor: pointer; border-radius: var(--radius); box-shadow: rgba(black, 0.1) 4px 4px; } .button:active { transform: translateY(1px); box-shadow: none; } .empty-cart { color: var(--color-mid); border-color: var(--color-mid); background-color: var(--color-light); }

Related: See More


Questions / Comments: