Say I have a "div" element with a border assigned to it. If the overflow rule for it is set to 'hidden', content that is ON the border of the "div" disappears.
Is there any way to overcome this? Because in my scenario, having content that is on the border not disappear is very important. I need the boundaries of my element to include the border too.
CSS Overflow. The overflow property specifies whether to clip the content or to add scrollbars when the content of an element is too big to fit in the specified area. The overflow property has the following values: visible - Default.
CSS Border Style The border-style property specifies what kind of border to display. The following values are allowed: dotted - Defines a dotted border
overflow-x specifies what to do with the left/right edges of the content. overflow-y specifies what to do with the top/bottom edges of the content. You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.
Unless a height is set, text will just push an element taller as well. Overflow comes into play more commonly when explicit widths and heights are set and it would be undesirable for any content to spill out, or when scrolling is explicitly being avoided. If you don’t set the overflow property at all, the default is visible.
I believe it will take three div's
to achieve this (maybe somebody can come up with a two div
solution). Here is an example fiddle. Three nested div
elements (the outer here has the .CropIt
class) with:
CSS
.CropIt {
overflow: hidden;
width: 60px;
}
.CropIt > div {
border: 20px solid red;
width: 20px;
}
.CropIt > div > div {
margin: -20px;
}
The outer sets the overflow to hide past the border hidden. The middle sets the width and border (which outer must match that total width or use float
to shrink wrap). The innermost set's the negative margin to push the content over the border of middle, and create the overlap of the border to the middle div
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With