html - 为什么我的 CSS 没有被覆盖?

标签 html css

<style type="text/css">
.x-container img {
    float: left;
    margin-right: 15px;
}
.content img{
    clear:both;
}
</style>

<div class="x-container span-18">
    <div class="content">
        <img src="image.jpg" id="disneland-img">
    </div>
    <h2>Hello</h2>
</div>

我有上面的 html。我期待 .content img 中的 clear:both 将覆盖 .x-container imgfloat:left,但事实并非如此。

请问我怎样才能做到这一点?

最佳答案

直接在图像上使用 clearfix 类,这将完成所有工作 将 clearfix 类放在带有内容类的 div 上。

<div class="x-container span-18">
    <div class="content clearfix ">
    <img src="image.jpg" id="disneland-img">
    </div>
<h2>Hello</h2>
</div>

.clearfix:before, .clearfix:after {
    content: "";
    display: table;
}
.clearfix:after {
    clear: both;
}
.clearfix {
    zoom: 1;
}

http://jsfiddle.net/wikijames/TVm6K/

关于html - 为什么我的 CSS 没有被覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16339324/

相关文章:

html - 溢出隐藏不适用于相对容器和绝对元素解决方案

javascript - 使用 Bootstrap 的响应式 3 列布局

javascript - Jscript element.style 在 script.js 中不起作用(Visual Studio 代码)

html - 两列布局 HTML/CSS

jquery - 如何在所有浏览器和所有设备的屏幕中央显示 Bootstrap 模态对话框?

html - 解决表格圆 Angular CSS

php - 为什么ajax在php中复制整个页面

javascript - 在移动设备中显示一个 Bootstrap 轮播元素

css - 在 [css] 中设置表格的 td 样式

jquery - 在 jquery 中禁用动态生成的按钮