开发者

Achieving a properly aligned sidebar in a DIV layout

开发者 https://www.devze.com 2022-12-27 18:44 出处:网络
I\'m experimenting with DIVs to align my page\'s contents: http://labs.pieterdedecker.be/test/test.htm

I'm experimenting with DIVs to align my page's contents: http://labs.pieterdedecker.be/test/test.htm

As you can see, there's something wrong with the sidebar. I got the sidebar DIV to be aligned to the right of the page by doing flo开发者_如何学编程at: right, but when the text in the sidebar stops the main area takes over the width that should be used by the sidebar.

How do I fix this?


I supose what you want to accomplish is to separate the #body div in 2 columns. First of all it will be easier if you package main column in its own div like this:

<div id="body">
    <div id="sidebar">lorem ipsum...</div>
    <div id="main">lorem ipsum...</div>
</div>

and then give #main div a width.

If you need to preserve your markup, then ALL #body elements other than #sidebar must have a width.

Another solution that would work if page is static and it's content will not "grow" is to set a big-enough heigth to the sidebar...

maybe what you are looking for is equal height columns... there are some differente method to do this... just google for it or take a look at this: http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks


You give the main area a width.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号