Boxpunch
So we can do it after all, even in IE for Windows! Notice how the border of the main div
is bent out of a rectangle so that it runs inside the floated element. Okay, I'm lying. That isn't what's really happening. Instead, I set one-pixel black borders on the right and bottom edges of the float, and no border at all on the top and left edges. Then the float is pulled one pixel up and one pixel to the left, which is accomplished by setting -1px
margins on those sides. This causes the float to overlap the border set on the main div
, thus covering up the black border with the white background of the float. In most recent browsers, that's enough, but in IE/Win we also have to relatively position the float in order for it to move. The code looks like this:
div#main2 {border: 1px solid black;} div#punch2 {float: left; width: 100px; height: 70px; text-align: center; background: white; color: black; border: solid black 1px; border-width: 0 1px 1px 0; padding: 0 10px 5px 0; margin: -1px 25px 10px -1px; position: relative;} /* fix for IE/Win */ div#punch2 img {height: 70px; width: 100px;}
The last line really shouldn't be necessary, and why it suddenly makes this technique work in IE/Win is something of a mystery. However, it does work in all the browsers that handled the original boxpunch, and then adds in IE/Win, so we'll not quibble too hard. Let us instead praise and congratulate Big John, who was the first to point out this exact workaround. (Other people had found similar approaches, but they all made the trick work in IE/Win at the expense of other browsers, which wasn't acceptable.)
As in the curvelicious demo, the h1
at the top is simply styled as normal, and its borders and background "slide under" the floated element. This is expected behavior in CSS2. If you were to set a left border on the h1
, you'd have to make it at least 111px
wide before it could be seen at all! Well, unless it become so tall that it was taller than the float. Then you'd be able to see it below the float. If your browser supports text zooming, try increasing the text size until the h1
is taller than the float. You should see what I mean then.