如何仅使用 CSS 创建 3 列布局?

发布于 12-28 20:15 字数 1189 浏览 1 评论 0原文

我正在尝试纠正页面内容部分有三列但 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

金兰素衣2025-01-04 20:15:23

您需要为每个 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/

我的影子我的梦2025-01-04 20:15:23

请添加“float:left;”在您的投资者 ID 中。 css是

#investor
{
background-image: url('../Images/Lender.jpg');
background-repeat: no-repeat;
width: 371px;
height: 248px; float:left;
}

谢谢

Please add "float:left;" in your investor id. The css is

#investor
{
background-image: url('../Images/Lender.jpg');
background-repeat: no-repeat;
width: 371px;
height: 248px; float:left;
}

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文