6

わかりました、私はCSSを初めて使用しますが、これは私に問題を引き起こしているだけです. すべての列ではなく複数の列に背景色を追加するにはどうすればよいですか。

span2 で 1 つの背景色が必要で、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 &raquo;</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 &raquo;</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 &raquo;</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

4

1 に答える 1

10

をレベルに設定するのbackground-colorは得策ではありません。span#なんで?は配置ヘルパーであるためspan#、パディングまたはマージンを変更すると、グリッド全体が壊れます。

では、色付きの背景ラッパーをレンダリングするためのネイティブ Twitter Bootstrap 要素は何でしょうか? ですwell

それの使い方?

まず、well要素を の中に挿入しspan#ます。

<div class="span5">
    <div class="well well-red">
        <!-- Your content -->
    </div>
</div>

次に、クラスの拡張機能を使用してプロパティを割り当てます.well(私は を使用しました.well-red):

.well-red {
    background-color: #ff0000;
}

このようにして、常に親クラスを利用.wellできますが、さまざまなプロパティを自由に適用できます。

于 2012-09-26T07:13:06.927 に答える