好的,我是 CSS 新手,这只会给我带来麻烦。如何将背景颜色添加到多列但不是所有列。
我想要 span2 上的一种背景颜色和 span10 上的另一种颜色。我遇到的问题是填充问题。当我将背景应用于某些列时,它不会在内容周围有很好的均匀填充。这有意义吗?如何为具有嵌套列的某些列添加背景并仍然保持良好的填充?
HTML
<div class="row bg">
<div class="span10">
<!-- Main hero unit for a primary marketing message or call to action -->
<div class="sidebar">
<div class="hero-unit">
<h1>Join</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-large">Register Now »</a></p>
</div>
</div>
<!-- Example row of columns -->
<div class="row">
<div class="span5">
<div class="bot-pad">
<h2>We are Fun!</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn" href="#">View details »</a></p>
</div>
</div>
<div class="span5">
<div class="right-pad bot-pad">
<h2>Learn more about yourself</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn" href="#">View details »</a></p>
</div>
</div>
</div>
</div>
</div>
CSS
.bg
{
background: url('/assets/img/grid.png');
.border-radius(5px); //LESS mixin for creating border radius
}
.right-pad
{
padding-right: 20px;
}
.bot-pad
{
padding-bottom: 20px;
}
解释
所以bg
班级正在应用背景。然后我的嵌套列有奇怪的填充,所以我经历并添加了类,比如right-pad
需要右填充的bot-pad
列和底部需要填充的列。我知道这在语义上是多么的错误,我只是不知道如何获得我需要的结果。谢谢。
这是我正在尝试做的另一个例子......但是他们也没有提供解决方案 https://github.com/twitter/bootstrap/issues/1446