My theory is that three div's
are needed to accomplish this (although someone may be able to devise a solution with just two div
). Check out this example fiddle. The setup consists of three nested div
elements (the outer one 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 div
controls hiding any content that extends beyond its borders. The middle div
specifies the width and border, which must match the total width of the outer div
or utilize float
for proper sizing. The innermost div
uses negative margins to shift the content over the border of the middle layer, creating an overlapping effect between the border and the middle div
.