2012-05-01 10 views
1

最近、6つの列にyオーバーフローが必要なウェブサイトを作成しました。私はきれいな6つの部門を作ることができませんでした。幅は、6つのスクロールバーと少しのパディングに合わせて調整する必要がありました。オーバーフローで画面を均等に分割する

私の試みよりも良い方法はありますか?

<div class="col"> 

    <div class="section"> 
    Content that overflows this section. 

    </div> 

</div> 

    .col { 

    width: 15.2%; 
    padding-right: 15px; 
    float: left; 
} 

.section { 
    overflow-y: scroll; 
    width: 100%; 


} 

これは非常にうっすらで、列は右端に届きません。

私はjqueryを試しても十分ではありませんが、アドバイスを受けたいと思います。 ** * ***

私はそう愚かな、それを働きました。あなたはパディングを含むすべてに%を使用する必要があります。 Duh ** * ****いつでも無駄な時間を無駄にしてしまいます!

+2

htのようなCSSグリッドフレームワークを使用してみてくださいtp://960.gs/レイアウトの作成にはすべての労力がかかります。 – luke2012

+0

そのリンクは、固定幅のレイアウト(主に960ピクセル)に基づくグリッドデザインを提供します。私は、opが設計したように、可変幅のデザインで非常に役立つとは思わない。 '%'を使うと確実に問題を解決できますが、ブラウザによっては '%'の計算値が多少ずれてしまうことがあります。 – sarcastyx

答えて

3

.sectionの内部にパディングを設定する方が良いので、.colの幅を調整する必要はありません。このCSSで

<div id="grid"> 
    <div class="col"> 
     <div class="section"> 
     Content that overflows this section. 
     </div> 
    </div> 
    <div class="col"> 
     <div class="section"> 
     Content that overflows this section. 
     </div> 
    </div> 
    <div class="col"> 
     <div class="section"> 
     Content that overflows this section. 
     </div> 
    </div> 
    <div class="col"> 
     <div class="section"> 
     Content that overflows this section. 
     </div> 
    </div> 
    <div class="col"> 
     <div class="section"> 
     Content that overflows this section. 
     </div> 
    </div> 
    <div class="col"> 
     <div class="section"> 
     Content that overflows this section. 
     </div> 
    </div> 
</div> 

このHTMLコードを試してみてください

#grid { 
    margin-left: -15px; 
} 

.col { 
    width: 16.6%; 
    float: left; 
} 

.section { 
    overflow-y: scroll; 
    margin-left: 15px; 
    height: 100px; 
    background: green; 
}​ 

#grid { margin-left: -15px; }

が見てあなたが最初の列の前に不要な空白を取り除くのに役立ちますのでご注意くださいLive demo

+0

私が欲しかったことを達成するためにはるかに良い方法です。どうもありがとうございました。 – uriah

+0

私はこのスニペットの高低を見てきました..大きな感謝! –

+0

@SPATENあなたは大歓迎です:) – aliona

関連する問題