Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show box-shadow outside of overflow area [closed]

Tags:

html

css

overflow

I have a few boxes inside a container. The container is set to overflow: hidden to make sure everything stays in its place. Taking away overflow: hidden is not an option because doing so allows content to overflow where it would otherwise resize to fit the container.

I'm trying to give the boxes a box-shadow, but when doing so, the shadows on the edge of the boxes at the edge of the container are not showing up (see image below), because the parent container stops there and has no overflow.

A cropped image showing a portion of four boxes within a container  each with a box-shadow: two at left; two at right.

As indicated by the green arrows, the two boxes at left show their shadows as expected. As indicated by the red arrows, the two boxes at right have their shadows cropped at the right edge where each meets the container.

Is there any way to hack around this?

A simple reproduction:
Note: This code snippet was added by a community editor, not the author, as an attempt to reproduce the symptoms. It does not reflect the actual code used by the author to produce the attached image.

.container {
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  column-gap: 1rem;
  row-gap: 1rem;
}

.shadow {
  display: inline-block;
  height: 2rem;
  background-color: tomato;
  box-shadow: 0 0 0.25rem black;
}
<div class="container">
  <div class="shadow"></div>
  <div class="shadow"></div>
  <div class="shadow"></div>
  <div class="shadow"></div>
</div>
like image 865
Ieuan Avatar asked Dec 12 '15 09:12

Ieuan


People also ask

How do I hide content of overflow?

Set the div with a width or height, (otherwise it won't know whether something is overflowing). Then, add the overflow:hidden; CSS property-value pair.

How do you get a box shadow on the bottom only?

For that, we can set h-offset to 0 and give some value to v-offset . As a result, the shadow will appear only at the bottom of the box. For example, create a box with a certain height and width. Set the background-color property to black .

What is blur radius in box shadow?

<blur-radius> This is a third <length> value. The larger this value, the bigger the blur, so the shadow becomes bigger and lighter. Negative values are not allowed. If not specified, it will be 0 (the shadow's edge is sharp).

How do you clip the overflowing content from an HTML element?

Use overflow-x : hidden and overflow-y : scroll , or overflow: hidden scroll instead. Use overflow: clip instead. As of Firefox 63, -moz-scrollbars-none , -moz-scrollbars-horizontal , and -moz-scrollbars-vertical are behind a feature preference setting.


1 Answers

Can you add margins to the inner div's?

    #inner-div {
      margin: 10px
    }

check this JSFiddle

like image 155
musafar006 Avatar answered Sep 18 '22 07:09

musafar006