html - 数量未知的水平行

标签 html css

我希望创建 X 个水平 float 的不同行。 (见图片。)我遇到的问题是我无法设置容器的宽度,因为我不知道将添加多少行。

目前我有这个:

HTML:

<div class="container">                  
            <div class="row">
                Lots of content
            </div>
            <div class="row">
                Lots of content
            </div>
            <div class="row">
                Lots of content
            </div>
            <div class="row">
                Lots of content
            </div>
        </div>

CSS:

.row  {
    float:left;
    width:23%;
    margin-left:1%;
    margin-right:1%;
    background-color:#252525;
    height:500px;
    color:white;
}

.container {
    width:500%;
}

每次添加或删除新行时,都需要更改容器的宽度。有什么办法可以解决吗?

Horizontal scrolling problem

最佳答案

您应该能够使用“flex”。

CSS:

.row {
  flex: 1;
}

.container {
  display: flex;
}

参见 http://www.w3schools.com/cssref/css3_pr_flex.asphttp://www.w3schools.com/cssref/pr_class_display.asp

关于html - 数量未知的水平行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26166431/

相关文章:

html - 使图像出现在悬停时

css - 使用 CSS 从谷歌应用脚​​本上传本地路径图像

html - CSS3 :not() selector, 处理包含的元素

具有水平扩展选择选项的 HTML 表单

javascript - HTML5 中的这段音频有什么问题?

javascript - 如何退出全屏模式并同时触发我自己的功能?

html - 带有类的第一个子实例的 CSS 选择器?

javascript - 带导航的简单 jquery 幻灯片?

css - Angular Material 13 - 如何更改 mat-form-field 边框的颜色

jquery动态罢工不起作用