Use box shadow inside scrollable div

box-shadow: inset
box-shadow generator
box-shadow on top of div
css box-shadow examples
box-shadow rounded corners
box-shadow only bottom
multiple box shadows
curved box-shadow css

I've a problem. I'm implementing a wrapper with 3 divs inside. Each div has a min width. When I shrink the browser and the min width get's reached, the overflow: auto get's enabled. The problem is now that my boy shadow get's cut off in this case. Maybe there is a way to handle this that the shadow is still there?

div {
  display: flex;
  overflow-x: scroll;
  overflow-y: hidden;
}

span {
  min-width: 300px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0.12rem 0.4rem 0 rgba(0, 0, 0, .2);
}

span:not(:last-child) {
  margin-right: 15px;
}
<div>
    <span>HI</span>
    <span>HI</span>
    <span>HI</span>
</div>

I think you need to add padding to the root of box.

simply add "padding: 5px;" to the "div" like this.

div {
  display: flex;
  overflow-x: scroll;
  overflow-y: hidden;
  padding: 5px;
}

span {
  min-width: 300px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0.12rem 0.4rem 0 rgba(0, 0, 0, .2);

}

span:not(:last-child) {
  margin-right: 15px;
}
<div>
    <span>HI</span>
    <span>HI</span>
    <span>HI</span>
</div>

CSS Box Shadow, Used in casting shadows off block-level elements (like divs). .shadow -webkit-​box-shadow: inset 0 0 10px #000000; box-shadow: inset 0 0  Required. The horizontal offset of the shadow. A positive value puts the shadow on the right side of the box, a negative value puts the shadow on the left side of the box: Play it » v-offset: Required. The vertical offset of the shadow. A positive value puts the shadow below the box, a negative value puts the shadow above the box

i put your code in code pen and i put margin in span selector and your box shadow won't go away

div {
  display: flex;
  overflow-x: scroll;
  overflow-y: hidden;
}

span {
  min-width: 300px;
  margin: 20px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0.12rem 0.4rem 0 rgba(0, 0, 0, .2);
}

span:not(:last-child) {
  margin-right: 15px;
}

if i'm wrong tell me maybe i can help you then

scrollbar, A brief history of styling scrollbars: It used to be a thing only Internet body::-​webkit-scrollbar-track { box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3)  The vertical offset (required) of the shadow, a negative one means the box-shadow will be above the box, a positive one means the shadow will be below the box. The blur radius (required), if set to 0 the shadow will be sharp, the higher the number, the more blurred it will be, and the further out the shadow will extend. For instance a shadow with 5px of horizontal offset that also has a 5px blur radius will be 10px of total shadow.

You can use this code

      span {
        min-width: 300px;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
/*        box-shadow: 0 0.12rem 0.4rem 0 rgba(0, 0, 0, .2);*/
        box-shadow: 0px 0px 10px rgba(0, 0, 0, .5) inset;
      }

Add Top and Bottom Scroll Shadows, An example on how to add top and bottom shadows on scroll to a Kendo UI Grid. wrap the .k-grid-element in a div element and, depending on the scroll position and the height of the Add inline CSS for styling the top and bottom shadows. <style> .box-shadow-wrapper { position: relative; } .box-shadow-wrapper table  Make the top and the bottom div very small in height, and add the box shadow to the middle div. The top and the bottom div will effectively hide the box shadow, if your z-index is in the right configuration. You might need to alter the z-index slightly to get this to work. I hope this helps!

Shadows, I thought I could contribute some key concepts about box shadow that might help that will cause scroll bars to occur if the rendered shadow fall outside the viewport. Assuming <div id="content"> <div id="content_inner"></div> </div> and wanted to go back to 'default' then use this: width:auto; instead of width:100%​  CSSmatic is a non-profit project, made by developers for developers. Are you a web developer? Would you like to collaborate on CSSMatic?

CSS Overflow, Therefore, a scrollbar is added to help the reader to scroll the content. You can use the overflow property when you want to have better control of the layout. div { width: 200px; height: 50px; background-color: #eee; overflow: visible; } value to scroll , the overflow is clipped and a scrollbar is added to scroll inside the box. All of the values here essentially perform the same way, only the shadow is placed inside of the box. Here we can see how the spread of a shadow can still have a big impact on how the shadow looks: Notice that this time I actually used RGBa color instead of a hex value.

CSS overflow property, box-shadow box-sizing break-after break-before break-inside caption-side Show different overflow property values: div.ex1 { overflow: scroll; } div.ex2 { property specifies what should happen if content overflows an element's box. by default and only shown when being used (even though "overflow:scroll" is set)​. Of course today we just use border-radius, but the idea is still relevant today. I used it here to create the illusion of the shadow appearing on scroll. In fact what is happening is that we reveal the shadow on scroll by making it sticky and then having a cover element that slides away with the page content.

Comments
  • You could add a padding to your container ?
  • @AmauryHanser I could but this would destroy the design :/