html - CSS Float Clear Both 50% width Div with Border

标签 html css

HTML

<div>
    <div class="leftInRow5050 squareTopLeft">1</div>
    <div class="rightInRow5050 squareTopRight">2</div>
    <div style="clear: both;"></div>
</div>
<div>
    <div class="leftInRow5050 squareBottomLeft">3</div>
    <div class="rightInRow5050 squareBottomRight">4</div>
    <div style="clear: both;"></div>
</div>

CSS

.rightInRow5050{
    width:50%;
    display: inline-block;
    float:right;
}

.leftInRow5050{
    width:50%;
    display: inline-block;
    float:left;
}
.leftInRow5050.squareTopLeft{
    height: 35%;
        border-right: 1px solid #CCCCCC;
    border-bottom: 1px solid #CCCCCC;
}

.rightInRow5050.squareTopRight{
    height: 35%;
    border-left: 1px solid #CCCCCC;
    border-bottom: 1px solid #CCCCCC;
}

.leftInRow5050.squareBottomLeft{
    height: 35%;
    border-right: 1px solid #CCCCCC;
    border-top: 1px solid #CCCCCC;  
}

.rightInRow5050.squareBottomRight{
    height: 35%;
    border-left: 1px solid #CCCCCC;
    border-top: 1px solid #CCCCCC;  
}

为什么上面的代码无法创建 2X2 <div>矩阵? 它给了我标准的 1px 问题,其中 <div>是彼此相克吗?

最佳答案

如果 div 有边框,而这就是它的问题,试试这个:

box-sizing:border-box;

关于html - CSS Float Clear Both 50% width Div with Border,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22349875/

相关文章:

javascript - 获取 contenteditable div 的当前行?

html - Opera Mini 4.2 上的链接选择行为异常

android - 使用 HTML 内容在 TextView 上进行额外填充

html - float 时基于百分比的最大宽度问题

javascript - 应用三次贝塞尔函数为属性更改设置动画

html - 如何从 ASCIIDoc 文件构建网站?

javascript - 使用 Node Clone 重复 HTML/PHP 代码

css - 对齐 html 表格内的文本

jquery - 并排 float 不等高的div

css - 我可以使用与内置字体同名的自定义@font-face 字体吗?