html - float div 留有 50vw

标签 html css

我有一堆 div,我想要在 2 列中使用 50vw 和 50vw 来制作一个完美的正方形。但是,当向左浮动时,它们不会彼此相邻,而是会在新的一行中移动。它必须具有响应性,所以我不能使用固定值。我该怎么做?

HTML

<div>A</div>
<div>B</div>
<div>C</div>
<div>D</div>
<div>E</div>

CSS

body {
    margin: 0px;
}

div {
    width: 50vw; 
    float: left;
    display: inline-block;
    height: 50vw;
    background: pink;
}

代码:http://jsfiddle.net/ryp829mk/8/

最佳答案

用显式宽度 = 100vw 将它们包裹在一个 div 中:

<div style = "width:100vw">
<div>A</div>
<div>B</div>
<div>C</div>
<div>D</div>
<div>E</div>
</div>

关于html - float div 留有 50vw,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28288876/

相关文章:

javascript - 如何将最大高度 css 属性指定为屏幕尺寸

javascript - Angular html 模板作为带有样式属性的字符串,渲染时没有样式属性

css - 使用 Blueprint CSS 框架时如何创建不带交替行颜色的表格?

Javascript : is it possible to target only one version of iOs?

jquery - Div 高度 100% 不起作用 - Bootstrap

html - 固定宽度容器内的动态 CSS 多列列表

html - 并排 Bootstrap 导航栏

html - 仅在悬停时出现的元素

html - CSS 导航栏调整大小问题

CSS 规则覆盖背景颜色的自定义规则