我不善于整合它的崩溃。 我浮动了很多东西,发现无论何时我开始浮动东西时,我都必须将其容器和容器容器浮起来,因为否则容器就会折叠。
所以看着我的网站现在它是一个非常稳定的,但如果我把身体上的边界,我看到它是顶部1px高,身体的一切都在外面。 如果我漂浮身体,那么一切看起来不错,但:
1-这是不好的设计,我该怎么做?
2-如果它确定我如何中心身体? 我使用margin:auto。 但一旦身体浮动,它就停止工作。
这是我的CSS。
body { width: 960px; font-size: 13px; margin: auto; margin-top: 20px; border: 1px #000 solid; } .wrapper { float: left; width: 960px; } .header { float: left; width: 960px; border: 1px #000 solid; margin-bottom: 20px; } .menu { width: 960px; float: left; border: 1px #000 solid; } .sidebar { width: 260px; float: left; margin-top: 20px; margin-left: 20px; } .content { border: 1px #000 solid; margin-left: 20px; margin-top: 20px; width: 620px; float: left; padding: 10px; } .footer { border: 1px #000 solid; width: 960px; float: left; margin-top: 20px; }和布局文件:
<body> <div class="wrapper"> <div class="header"> <h1>HEADER</h1> </div> <div class="menu"> <ul> <li><a href="/">Home</a></li> </ul> </div> <div class="sidebar"> sidebar </div> <div class="content"> <h1>Content</h1> </div> <div class="footer"> <h1>FOOTER</h1> </div> </div> </body>反正希望我清楚。
I am bad at integration its crasy. I float a lot of my stuff and find that whenever I start floating something I have to float its container ans its containers container ad nauseum because otherwise the container is collapsed.
So looking at my site now its pretty nice a stable but if I put a border on body I see that it is 1px high on top and everything in body is outside. If I float body then everything looks good but:
1- Is that bad design and how should I do it?
2- If its ok how do I center body? I use margin: auto. But once body is floated it stops working.
This is my css.
body { width: 960px; font-size: 13px; margin: auto; margin-top: 20px; border: 1px #000 solid; } .wrapper { float: left; width: 960px; } .header { float: left; width: 960px; border: 1px #000 solid; margin-bottom: 20px; } .menu { width: 960px; float: left; border: 1px #000 solid; } .sidebar { width: 260px; float: left; margin-top: 20px; margin-left: 20px; } .content { border: 1px #000 solid; margin-left: 20px; margin-top: 20px; width: 620px; float: left; padding: 10px; } .footer { border: 1px #000 solid; width: 960px; float: left; margin-top: 20px; }And the layout file:
<body> <div class="wrapper"> <div class="header"> <h1>HEADER</h1> </div> <div class="menu"> <ul> <li><a href="/">Home</a></li> </ul> </div> <div class="sidebar"> sidebar </div> <div class="content"> <h1>Content</h1> </div> <div class="footer"> <h1>FOOTER</h1> </div> </div> </body>Anyways hope I am clear.
最满意答案
用.wrapper overflow: auto替换float overflow: auto ,它应该工作得很好。 然后你可以用margin: auto来居中margin: auto :
.wrapper { overflow: auto; margin: auto; width: 960px; }此外,删除width: 960px和margin: auto从body因为你不需要他们了。
Replace the float with overflow: auto in .wrapper and it should work just fine. You can then center it with margin: auto:
.wrapper { overflow: auto; margin: auto; width: 960px; }Also, remove width: 960px and margin: auto from body as you don't need them anymore.
更多推荐
发布评论