Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS overflow rule includes object border?

Tags:

html

css

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.

like image 290
Andrei Oniga Avatar asked May 09 '12 17:05

Andrei Oniga


People also ask

What is overflow in CSS?

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.

What is border-style in CSS?

CSS Border Style The border-style property specifies what kind of border to display. The following values are allowed: dotted - Defines a dotted border

What is the difference between Overflow-X and overflow-y?

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.

What happens if you don’t set text overflow in HTML?

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.


1 Answers

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.

like image 122
ScottS Avatar answered Sep 28 '22 15:09

ScottS