如何仅使用 CSS 创建 3 列布局?
我正在尝试纠正页面内容部分有三列但 DIV 未正确浮动的问题。这是我的 HTML:
<div id="content">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="columns">
<div id="borrower">
</div>
<div id="dealer">
</div>
<div id="investor">
</div>
</div>
<div class="footer">
</div>
这是我的 CSS:
body{
font-family:Verdana, Geneva, sans-serif;
font-size: 10px;
width:100%;
height: 100%;
}
#content
{
background-image: url('../Images/background_03.jpg');
background-repeat: no-repeat;
width: 1150px;
height: 399px;
}
#borrower
{
background-image: url('../Images/Borrower.jpg');
background-repeat: no-repeat;
width: 371px;
height: 248px;
float: left;
}
#investor
{
background-image: url('../Images/Lender.jpg');
background-repeat: no-repeat;
width: 371px;
height: 248px;
}
#dealer
{
background-image: url('../Images/dealer.jpg');
background-repeat: no-repeat;
width: 371px;
height:248px;
float: right;
}
#footer
{
clear:both;
}
使用上面的代码,贷款人 DIV 位于借款人 DIV 的正下方,而不是位于借款人和经销商之间的中间。我该如何纠正这个问题?
I'm trying to correct an issue where the content section of my page has three columns but the DIVs are not floating appropriately. Here's my HTML:
<div id="content">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="columns">
<div id="borrower">
</div>
<div id="dealer">
</div>
<div id="investor">
</div>
</div>
<div class="footer">
</div>
Here's my CSS:
body{
font-family:Verdana, Geneva, sans-serif;
font-size: 10px;
width:100%;
height: 100%;
}
#content
{
background-image: url('../Images/background_03.jpg');
background-repeat: no-repeat;
width: 1150px;
height: 399px;
}
#borrower
{
background-image: url('../Images/Borrower.jpg');
background-repeat: no-repeat;
width: 371px;
height: 248px;
float: left;
}
#investor
{
background-image: url('../Images/Lender.jpg');
background-repeat: no-repeat;
width: 371px;
height: 248px;
}
#dealer
{
background-image: url('../Images/dealer.jpg');
background-repeat: no-repeat;
width: 371px;
height:248px;
float: right;
}
#footer
{
clear:both;
}
Using the above code, the Lender DIV is directly below the Borrower DIV instead of sitting in the middle between Borrower and Dealer. How do I correct this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您需要为每个 div 元素使用 float:left,而不是 float:right。除非您希望其中一个元素远离其他两个元素。如果要在 div 元素之间添加间距,请使用 margin-left。
http://jsfiddle.net/TxD6V/
Rather than float:right you need to use float:left for each div elements. Unless you want one of your elements to be positioned away from the other two. If you want to add spacing between the div elements use margin-left.
http://jsfiddle.net/TxD6V/