css - 除主 div 外的响应块
问题描述
我{width:100%; max-width: 900px}
在身体上有一个主要的 DIV。
我需要在左边的可用空间上再放置一个 DIV,在右边的空间上再放置一个。可以在没有 Javascript 的情况下完成吗?怎么做?
解决方案
您可以使用 flex 来实现您想要的:
.container {
display:flex; /* make container flex */
flex-direction:row; /* line up children in a row */
width:100%;
}
.center { /* this is your main div */
width: 100%;
max-width: 900px;
height: 200px; /* test value only */
background:green;
}
.col {
flex-grow:1; /* make side columns grow to fill any remaining space */
background:blue;
}
<div class="container">
<div class="col"></div>
<div class="center"></div>
<div class="col"></div>
</div>
推荐阅读
- python - 如何将 pip 命令的结果存储到 Pandas Datafarme
- linux - 用于返回小时和分钟用户的 Bash 脚本已被记录
- javascript - 如何计算两张像附件这样的黑白图片的相似度
- apache-nifi - 尼菲|| 结合来自多个 Putsql 处理器的流文件并与其他进程组连接
- javascript - 用 2 个参数模拟下一个函数?
- excel - 如何使用 PhpSpreadsheet 评估 CSE 公式?
- netlogo - Netlogo 模型中选择器的使用规则
- python - 我如何计算有多少项目出现一次、两次、三次……?
- javascript - 用 svg 变换旋转错误
- reactjs - FlatList中动态不同的对象