首页 > 解决方案 > Bootstrap:当只有 col-12 时不使用 col 的坏风格?

问题描述

只使用是不好的风格(甚至是危险的)

 <div class="row">Text</div>

代替

 <div class="row"><div class="col-md-12">Text</div></div>

当需要的列不超过一列时?

标签: htmlcsstwitter-bootstrap

解决方案


是的。.row通常有负边距来抵消最外面的.col左/右填充。比较这两个实例有无.col使用。

.col

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="container"><div class="row bg-primary"><div class="col">This text is inside row > col</div></div></div>

没有.col

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="container"><div class="row bg-primary">This text is inside row</div></div>


推荐阅读