效果图
图中效果只需要flex和margin便可以实现。
文章来源:https://www.toymoban.com/news/detail-829872.html
html
<div class="w_100_ d_f h_168 p_6 bc_c0c0c0">
<div class="w_50 h_50 bc_e75f57 m_a"></div>
</div>
<div class="w_100_ d_f p_6 mt_20 bc_c0c0c0">
<div class="w_50 h_50 bc_e75f57"></div>
<div class="w_50 h_50 bc_f2b64c"></div>
<div class="w_50 h_50 bc_55bd4c ml_a"></div>
</div>
<div class="w_100_ d_f p_6 mt_20 bc_c0c0c0">
<div class="w_50 h_50 bc_e75f57"></div>
<div class="w_50 h_50 bc_f2b64c"></div>
<div class="w_50 h_50 bc_55bd4c ml_a"></div>
<div class="w_50 h_50 bc_e75f57"></div>
</div>
<div class="w_100_ d_f p_6 mt_20 bc_c0c0c0">
<div class="w_50 h_50 bc_e75f57"></div>
<div class="w_50 h_50 bc_f2b64c"></div>
<div class="w_50 h_50 bc_55bd4c ml_a mr_a"></div>
<div class="w_50 h_50 bc_e75f57"></div>
</div>
<div class="w_100_ d_f p_6 mt_20 bc_c0c0c0">
<div class="w_50 h_50 bc_e75f57"></div>
<div class="w_50 h_50 bc_f2b64c ml_a mr_a"></div>
<div class="w_50 h_50 bc_55bd4c ml_a mr_a"></div>
<div class="w_50 h_50 bc_e75f57"></div>
</div>
<div class="w_100_ d_f p_6 mt_20 bc_c0c0c0">
<div class="w_50 h_50 bc_e75f57"></div>
<div class="w_50 h_50 bc_f2b64c ml_a"></div>
<div class="w_50 h_50 bc_55bd4c ml_a"></div>
<div class="w_50 h_50 bc_e75f57 ml_a"></div>
</div>
<div class="w_100_ d_f fw_w p_6 mt_20 bc_c0c0c0">
<div class="item w_50 h_50 bc_e75f57"></div>
<div class="item w_50 h_50 bc_f2b64c"></div>
<div class="item w_50 h_50 bc_55bd4c"></div>
<div class="item w_50 h_50 bc_e75f57"></div>
<div class="item w_50 h_50 bc_f2b64c"></div>
<div class="item w_50 h_50 bc_55bd4c"></div>
<div class="item w_50 h_50 bc_e75f57"></div>
<div class="item w_50 h_50 bc_f2b64c"></div>
<div class="item w_50 h_50 bc_55bd4c"></div>
<div class="item w_50 h_50 bc_e75f57"></div>
<div class="item w_50 h_50 bc_f2b64c"></div>
<div class="item w_50 h_50 bc_55bd4c"></div>
<div class="item w_50 h_50 bc_e75f57"></div>
<div class="item w_50 h_50 bc_f2b64c"></div>
<div class="item w_50 h_50 bc_55bd4c"></div>
<div class="item w_50 h_50 bc_e75f57"></div>
</div>
css
.item {
--n: 7;
--gap: calc((100% - 50px * var(--n)) / var(--n) / 2);
margin: 10px var(--gap);
}
解析
1、d_f:
display: flex;
2、fw_w:flex-wrap: wrap;
3、m_a:margin: auto;
4、ml_a:margin-left: auto;
5、mr_a:margin-right: auto;
3、item类名比较特殊,所以单独定义,涉及到变量,不属于公共样式
4、其他类名基本是见名知意,不做过多叙述文章来源地址https://www.toymoban.com/news/detail-829872.html
到了这里,关于web前端之使用弹性和外边距进行网页布局、非常有用的小技巧、flex、margin、auto的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!