注: これは、別の理由で絶対配置が必要なく、これが 2 つの列だけである場合に機能します。
他の解決策があります:
以下の方法を使用すると、自動値を使用してブロック レベルの要素 (div) をコンテンツに合わせて縮小しますが、固定幅のサイドバー、バナー、およびさらに追加して拡張する可能性を維持します。これは、最も簡単な 2 列の CSS レイアウトの 1 つをわずかに変更したもので、ほとんどの人はバナーをコンテンツ領域全体の上部に広げます。
NESTED という用語を理解するための読み取り専用
次の場合、ネストされた div は div 内の div です。div2 はネストされた div です。
<div class="div1"><div class="div2></div></div>
CSS
/* for centered page or disregard margin settings*/
.container{height: auto; margin: 0 auto;)
/* then nested inside .container have the following two: */
.sidebar(width: 195px; float: left; height: 100%;)
.col{width: auto; height: 100%;}
/* All of your other elements at this row-level in your document flow should be contained either within .sidebar or .col to start a new row research the CSS clearfix - not to say you couldn't place as many things as you want in the body column and align them by default relative to its container(.col) but I am saying for more advanced layouts and for layouts that REQUIRE absolute positioniong. Also note the auto width. I left the sidebar width at auto as well. The div will shrinkwrap to its contents. . . as long as they're square */
.banner{vertical-align: top; width: auto; height: auto;)
div.container で始まる HTML マークアップ
<div class="container">
<div class="sidebar">
sidebar contents
</div>
<div class="col">
<div class="banner">
<img src="path/to/banner.jpg" alt="what you want mouse-over to say" />
</div>
</div>
</div>
<!--- Research the CSS clearfix if your document requires the use of floats for a new row a content or if you must use absolute positioning. Absolute positioning is the future and there is specification in CSS3 to bring in an interesting feature that would eliminate grid framework systems. I wish I could find the link but it is basically you assign place-holders to a template and css uses the selectors and place holders using absolute positioning to style the page. In all reality abs positioning is the "ideal" way to do things. It is just not the practical way for most sites atm, nor does it have much to offer for simple layouts. --->
<div class="clearfix"></div>
経験のある方から大切なことをお伝えします。浮かんでいるこれらすべてのグリッド システムに巻き込まれないでください。プリセットのタイポグラフィ セットなどのブート ストラップ機能を提供するという意味でクールなものもありますが、結局のところ (Java スクリプト グリッドを除く) それらは通常、継承された左マージン、コンテナー、およびコンテナーを持つ固定幅の列だけです。オブジェクトを移動して任意のグリッド列に揃えるための左余白クラス。これらは学習に適しているため、標準を使用する必要があると思いますが、巨大なビューポートを備えたデスクトップで誰かに大規模で派手なユーザー エクスペリエンスを提供したい場合は、メディア クエリを使用してください。一般的なルールは次のとおりです。要素がピクセル パーフェクトでない場合、要素は正しく表示されません。グリッドはこれを保証しますが、好みに合わせてカスタマイズします。デザインには三分割法などの魅力的なアスペクト比があるため、これは原則です。その他、見た目に美しい自然除数があるため、設計上の決定時にグリッドに実装することをお勧めします。