I have two divs formatted as panels. One is the main panel whereas the other is something like a sidebar. I would like the sidebar to float to the left, but the latter is embedded inside the main div. I want it to display next to the main panel, rather than inside it.
I know I could float the sidebar left, the main panel right and add some more content after them and use clear: both to make the page resize and scroll properly; this sounds like a hack, however, and it requires specifying the size of both panels. If I could float just the sidebar to the left, then the main panel would size itself automatically to cover the rest of the page.
My HTML code at the moment looks something like this:
<div id="sidebar" class="panel">
Sidebar
</div>
<div id="content" class="panel">
<p>Content</p>
<p>Content</p>
<p>Content</p>
</div>
And the CSS of interest is:
#sidebar {
float: left;
width: 30%;
}
In the screenshot below, one can easily see that the sidebar is floating to the left, but is somehow inside the main panel. In the HTML code, however, the sidebar is clearly outside the main panel. How can I fix that without having to use float: right on the main panel?

float: lefton the main panel?float: left/righton the main panel would require specifying its size, since it won't cover the rest of the screen anymore. I know how to do it in an ugly way:main panel->float right,sidebar->float left, a hiddenhrafter those that usesclear: bothand specifying the size for both panels manually. I am looking for an elegant solution that could work by specifying just the size of the sidebar.#content { overflow: hidden; }