Simple sidebar problem

I’m having some issues with a simple sidebar. With the browser at full size, it should be 320px wide, and the main content should resize to fit the 960px container. For some reason, the sidebar is getting pushed to the bottom. Please advise. Thank you.

#container-page { margin: 0 auto; padding: 50px 0; max-width: 960px; text-align: left; overflow: auto; } #main { padding: 0; margin: 0; } #sidebar { padding: 0; margin: 0; } @media screen and (min-width: 640px) { #main { float: left; } #sidebar { width: 320px; float: right; } }

http://wearabletechforums.com/v2/select.php

Basically the #main can be as big as it wants since it has no width.

Put the sidebar element BEFORE the main element, unfloat main, and give main margin-right:320px;

If you messed something up (e.g. what I say doesn’t work), then undo and try again until it works.

With your current setup (with main and sidebar floated, you’d have to set a width for the main area to make room for the sidebar. Otherwise #main will be the default full width.

The standard way to do what you want is to unfloat the main section and give it a right margin large enough to make room for the sidebar. But then you’d have to place the sidebar div above the main div in the HTML.

Other options are to use table display or these days flex layout. There are also more complex workarounds from yesteryear, but I wouldn’t go for them any more.

EDIT: ninjad!

1 Like

Thanks!!

Oh—actually there is a problem with this. I set my sidebar to shift below the main content and expand to 100% width, but by moving the sidebar HTML above the main content, now it expands on top of the main content! What’s the alternative to this?

Link? The original page doesn’t show this—or even the sidebar any more.

I got rid of it, at least for now. The description should be pretty self explanatory, though. If there are two DIVs, the first of which is a sidebar, and then the sidebar turns into a 100% width block element at mobile dimensions, the sidebar will end up coming before the main content.

Yeah, as I said earlier, look at something like display: table on larger screens, or investigate flexbox.

As others have said display:table-cell is the way to go and the method I prefer these days where ie8+ support only is required (you can always float for ie7 and under if needed anyway)

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
h1{text-align:center;}
#container-page {
    margin: 0 auto;
    padding: 50px 0;
    max-width: 960px;
    width:100%;
    display:table;
    text-align: left;
}
#main,#sidebar {
    width:auto;
    display:block;    
}

@media screen and (min-width: 640px) {
    #main,#sidebar {
        display:table-cell;
        vertical-align:top;
    }
    #sidebar {width: 320px;}
}
</style>
</head>

<body>
<h1>IE8+</h1>
<div id="container-page">
        <div id="main">
                <h2>Main section</h2>
                <p>Lorem ipsum content lorem ipsum content lorem ipsum content lorem ipsum content lorem ipsum content lorem ipsum content lorem ipsum content lorem ipsum content </p>
        </div>
        <div id="sidebar">
                <h3>Sidebar</h3>
                <p>Lorem ipsum content lorem ipsum content lorem ipsum content lorem ipsum content lorem ipsum content lorem ipsum content lorem ipsum content lorem ipsum content </p>
        </div>
</div>
</body>
</html>

I’m finding this method so much more robust than floats and has the benefit of normal source order also.

Thanks!

I’m having some issues with table-cell now.

[code]



Text


Buttons

[/code] ![|690x27](upload://vMQoL8Ig19gqQs4D8Mwsbix7Mqv.png) [code]#container-columns { display: table; width: 100%; } #select-text { display: table-cell; background-color: blue; width: 100%; max-width: 640px; } #select-share { display: table-cell; width: 320px; background-color: red; }[/code] ![|690x21](upload://z1TdXni0mBhx60Dhhch8jgfkTdg.png) [code]#container-columns { display: table; width: 100%; } #select-text { display: table-cell; background-color: blue; max-width: 640px; } #select-share { display: table-cell; width: 320px; background-color: red; }[/code]

Care to elaborate :blush: ?

Fixed! I set container-columns as a class rather than an ID. Sorry, and thanks.

Okay. So, is there any reason why if I use table-cell like so, the left cell (with a bottom border) is higher than the bottom of the right cell?

#container-columns { display: table; width: 100%; margin-bottom: 30px; } #select-text { display: table-cell; max-width: 800px; padding: 15px 0; border-top: 2px solid #999; border-bottom: 1px solid #CCC; vertical-align: top; } #select-textbox { font-size: 175%; } #select-share { display: table-cell; width: 160px; padding-left: 15px; vertical-align: top; }

[code]



Design your own wearbles comparison by selecting up to 6 wearables.
You can also select one of our popular comparisons, organized by category, brand, or other specification.
If you’d like to compare a wearable that does not already appear in our collection, please let us know.



links

[/code]

Got a website for me?

Not appearing for me.

Most likely though it might be the padding you have set on #select-text. Try removing that and see if it helps.

Ah, I had a couple names reversed. Sorry. It’s the dteails!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.