I need to put more thought into these things before replying. My approach to it was all wrong. Floating elements is just fine until they run into each other. Then they'll fall one above the other on the y-axis rather than sharing the same area. For this, you need absolute positioning, but just a touch.
Here's what's in my CSS file:
code:<HR>
Code:
BODY {
margin: 12px;
}
#bigBox {
border: 1px solid #000;
height: 200px; /* take out before use */
margin: 0 100px;
padding-right: 100px;
}
#littleBox {
position: absolute;
top: 100px;
right: 14px;
background-color: red;
border: 1px solid #000;
width: 200px;
}
and here's what's in my XHTML file:
code:<HR>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
<head>
<title>Test</title>
<meta http-equiv="Content-type" content="text/html; charset='UTF-8'" />
<style type="text/css">
@import "global.css";
</style>
</head>
<body>
<div id="bigBox">
<p>Content</p>
</div>
<div id="littleBox">
<p>Content</p>
</div>
</body>
</html>
You'll notice the line in the CSS file with the comment "take out before use." That height declaration is there solely to show you what it looks like without a bunch of content in there. I used a bunch of filler text before but I wasn't going to post it all here. So I just added that height property to show you the outline of the bigBox extending below the littleBox rather than ending above it (load this stuff up, then take that line out and you'll see what I mean).
Here's what I did and why I did it:
I made the littleBox absolutely positioned. It's 100px from the top of the page (this is an arbitrary value) and 14px from the right-hand side of the page. This is because the body margin is also 12px (an arbitrary value) and the <div>'s border of 2px total (if you remove the border or use a different border width, you'll need to change the right:14px value to accommodate).
I gave the bigBox a left/right margin of 100px. That's half the width of the littleBox. This is so that half of the littleBox will appear in the bigBox and half will appear outside it.
I gave the bigBox a padding-right of 100px. That's to account for the space taken up by the littleBox. Because I used absolute positioning on the littleBox, it overlaps the content in the bigBox. You can either do this or use a float:right workaround with some empty <div> element so that your content will wrap around the box. But such a workaround would be a lot of trouble, it wouldn't have the complete desired effect, and having the positioned box be taller than your workaround box would cause problems. So I recommend the padding because it's easy and it works.
There may be other things you want explained. Feel free to ask and I'll answer to the best of my ability. Also, I only tested this in IE6. I'm not on my Web-dev box so I can't tell you how it works in other browsers.