html - 清除两个在 css 中的第一个 child 的高度

标签 html css

我使用了很多 float 和 clear 但在这种情况下我遇到了一个奇怪的问题。 这是我的 html 代码:

    .tablerow{
        border:1px solid blue;
        padding:0px;}
    
    .tablerow .tablerowcolumn{
        height:30px;
        width:15%;
        margin:0px;
        float:right;
        border:1px solid #565656;   
        background-color:#fff; 
    }
    <div class="tablerow">
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div style="clear:both"></div>
    </div>
    <div class="tablerow">
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div style="clear:both"></div>
    </div>

但是结果和预期的不一样:

enter image description here

最佳答案

您的代码有效,但不完全符合预期,因为 .tablerow 没有 height 属性,他们正试图尽可能少。

因此,如果您添加一个高度(例如 100 像素),您将得到以下结果:

    .tablerow{
        border:1px solid blue;
        padding:0px;
        height:100px;
    }
    
    .tablerow .tablerowcolumn{
        height:30px;
        width:15%;
        margin:0px;
        float:right;
        border:1px solid #565656;   
        background-color:#fff; 
    }
    <div class="tablerow">
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div style="clear:both"></div>
    </div>
    <div class="tablerow">
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div class="tablerowcolumn">
        </div>
        <div style="clear:both"></div>
    </div>

关于html - 清除两个在 css 中的第一个 child 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54977390/

相关文章:

css - 智能手机、平板电脑的纵向和横向查询

javascript - 我如何撤消子字符串(例如将文本返回到其正常长度)

css - html代码中的颜色文本

css - 在开发自己的模板时注释掉未使用的 CSS?

html - 两个谷歌地图重叠

html - height=100% 不起作用

javascript - 如何使用 jquery 在 html 多选框中创建 "select all"选项?

html - 如何在 CSS3 的导航栏上创建按钮链接?

html - 为什么 angular-datatable 不在 bootstrap 4 中填充 col?

html - 如何使用 col-md-4 类制作一行,我可以在其中放置完全相同尺寸的图像?