html - HTML & CSS 以百分比或视口宽度设置项目周围的空间宽度
问题描述
您好我正在尝试设置相同宽度的 flex 项目,因此宽度.flexbox
将与 相同.width-example
,这将是%或vw
这是一个简单的例子,它应该是这样的:
.width-example {
width: 80%;
height: 50px;
background-color: blue;
margin-left: auto;
margin-right: auto;
}
.flexbox {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
.flex-item {
width: 175px;
height: 175px;
background-color: green;
margin: 10px auto;
}
<div class="width-example"> </div>
<div class="flexbox">
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
</div>
解决方案
您正在设置宽度,.width-example
但不是您的.flexbox
. 将 awidth
和 a添加margin
到您的.flexbox
.flexbox {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
width: 80%;
margin-left: auto;
margin-right: auto;
}
推荐阅读
- flutter - Json解码转换为List
而不是地图 - javascript - p5.js 中的矩形对象网格
- python - 如何写入文件名中包含空格和特殊字符的文件?
- php - Eloquent:仅过滤具有相关“子”行的行
- ios - Flutter : 在 iOS 版本的 YouTube App 中打开视频
- javascript - 反应传单标记旋转
- javascript - 获取节点问题
- python - python - 编写一个字典,其值为不带括号的 csv 整数列表
- google-apps-script - 如何让谷歌表格根据排名重新排序
- javascript - 如何使用 JavaScript 选择字符串的最后一个字符?