html - 3 列 Div 样式

标签 html css

由于一些奇怪的原因,我无法让它正常工作(对于 3 列布局),它们显示时好像它们在不同的行上。 ------------------CSS----------------

.left_content{
    float:left;
    position:relative;
    width:30%;
    padding:10px;
    margin-right:0px;
    margin-left:0px;
    border-style:solid;
    border-width:2px;
    background-image: url(../images/right_divider.gif);
    background-repeat: no-repeat;
    background-position: left bottom;   



}


.center_content{
    float:left;
    position:relative;
    width:40%;
    padding:10px;
    margin-left:10%;
    border-style:solid;
    border-width:0px;
    background-image: url(../images/right_divider.gif);
    background-repeat: no-repeat;
    background-position: left bottom;   

}
.right_content{
    float:right;
    position:relative;
    width:20%;
    padding:10px;
    border-style:solid;
    border-width:0px;
    background-image: url(../images/right_divider.gif);
    background-repeat: no-repeat;
    background-position: left bottom;   

}
---------------html--------------
<div class="left_content">
    Nav Left
    </div>


    <div class="center_content">
    main Con<br>main Con<br>main Con<br>main Con<br>main Con<br>main Con<br>main Con<br>
    </div>


<div class="right_content">
    right Con
    </div>

最佳答案

@弗兰克;正如您在代码中看到的那样,三个 div's 的总宽度超过 100%。原因是 paddingborder 是给 div 添加宽度。因此,您可以为此使用 css3 box-sizing 属性。它停止填充以增加 div 的宽度。

CSS:

-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;

检查这个例子http://jsfiddle.net/wVfeG/

注意:IE7 不支持box-sizing 属性。因此,您可以从您的 div 中删除 padding 并为其子元素提供 margin

关于html - 3 列 Div 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6677934/

相关文章:

python - 获取特定行的内容

html - svg 的一部分在转换后被隐藏

w3c - 是否有 CSS3 供应商前缀的浏览器兼容性弃用表?

css - Flexbox children 并不总是扩展到他们可以/应该的那么宽

css - 使用框阴影模拟分页符

html - 将表格列的宽度设置为在其下方行的内容宽度处达到最大值

javascript - 从变量更改 div 的 css

html - 如何将 img 与文本内联

javascript - 使用 Angular 2 在 HTML5 中动态定义输入类型

https - 当我使用 https 将它移动到另一个站点时,我的 css3 媒体查询将不起作用