css - DIV 框未对齐

标签 css html alignment

我在尝试让 col3 和 col4 对齐时遇到问题。我得到下面的内容 - 我试图让它们在红色框中相互对齐。

enter image description here

HTML:

<div class="listingAttributes">
<div class="col0">
<span class="name">Bedrooms:</span>
<span class="value">2</span>

<span class="name">Bathrooms:</span>
<span class="value">4</span><br/>

<span class="name">Price:</span></br>
<span class="value">Asking price $1,250,000</span></p>                                                          
</div>
<div class="col1">
<span class="name">Floor area:</span>
<span class="value">200m²</span>
<span class="name">Land area:</span>
<span class="value">1452m²</span>
<span class="name">Rateable value</span>
<span class="value">$980,000</span>                                                                     
</div>
<div class="col2">
<span class="name">Open home times:</span>
<span class="value">
<p>Sat 1 Dec 2 pm - 2:45pm</p>
<p>Sun 2 Dec 2 pm - 2:45pm</p>

</span>
</div>

<div class="col3">
<span class="name">In the area</span><br/>
<span class="value">Schools, Cafe's, Orewa Beach, Surfclub, Orewa Village, Silverdale Mall Wenderholm Park. Boat Ramp</span>
</div>
<div style="clear:both"></div>
<div class="col4">
<span class="name">In the area</span><br/>
<span class="value">Schools, Cafe's, Orewa Beach, Surfclub, Orewa Village, Silverdale Mall Wenderholm Park. Boat Ramp</span>
</div>
</div>

CSS:

.listingAttributes{
    width:100%;
    height:100%;
    margin: 15px 10px -5px 10px;
    border-bottom: 1px solid #FFB400;
    background-color: red;
}
.listingAttributes .col0, .col1{
    width:160px;
    height: 100%;
    margin:0 15px 0 0;
    float:left;
    display: inline-block;
}
.listingAttributes .col2{
    width:180px;
    height: 100%;
    margin:0 15px 0 0;
    float:left;
    display: inline-block;
}

.listingAttributes .col3{
    width:350px;
    float:left;
    background: green;
    display: inline-block;
}
.listingAttributes .col4{
    width:350px;
    float:right;
    background: green;
    display: inline-block;   
}
.listingAttributes .sectionListingAttributes, .name{
    font-weight: bold;
}

最佳答案

清除您的父类 .listingAttributes

.listingAttributes{
overflow:hidden;
}

--------

我认为你应该删除 display:inline-block,因为你正在使用 float 并且对你的 parent 来说是清晰的

<强> Live Demo

关于css - DIV 框未对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13639537/

相关文章:

css - 本地主机 (Wamp) 上的 Symfony Assets

html - 页面中的 CSS 在移动网站上溢出

javascript - 如何在 safari 和 chrome 的选择框(下拉框)中设置高度或填充?

css - 将子 div 在父级中居中/底部对齐

jquery - 元素的对齐和视差移动

css - 在移动设备上隐藏文本并隐藏在移动设备上方的尺寸上

javascript - 输入类型=附加到 onclick 事件的文件

html - CSS 按钮悬停效果(边框更改、背景更改)不起作用

javascript - 三星智能电视 SDK 5.1 应用程序开发

CSS:我可以通过 margin: 0 0 0 auto 右对齐一个元素吗?