2011-12-05 16 views
4

私は現在、私のためにウェブサイトのテンプレートを設計しようとしています。問題は、コンテンツdivがその中にあるコンテンツに対して自動的に展開されないことです。CSSコンテンツを作成するDIVコンテンツの後の自動サイズ

私は自動的にサイズを変更したいので、CSSの高さを手動で設定する必要はありません。

私が作ったCSSコード:

#Container { 
    position: relative; 
    width: 800px; 
    height: 100%; 
    margin: 0px auto 0 auto; 
    text-align: left; 
    padding-left: 1px; 
    cursor: de; 
    border-left: 1px solid #000001; 
    border-right: 1px solid #000001; 
    border-top: 1px solid #000001; 
    border-bottom: 1px solid #000001; 
    background-color: #C1E9FF; 
} 
#LogoContainer { 
    background-image: url('/media/Logo.png'); 
    border-right-width: 1px; 
    border-bottom-width: 1px; 
    border-right-color: rgb(0,0,1); 
    border-bottom-color: rgb(0,0,1); 
    border-right-style: solid; 
    border-bottom-style: solid; 
    width: 400px; 
    height: 50px; 
    position: absolute; 
    z-index: 1; 
} 
#LikeBar { 
    border-bottom-width: 1px; 
    border-bottom-color: rgb(0,0,1); 
    border-bottom-style: solid; 
    width: 400px; 
    height: 50px; 
    position: absolute; 
    left: 400px; 
    z-index: 1; 
} 
#ButtonHome { 
    background-image: url('/media/Bt.png'); 
    width: 100px; 
    height: 30px; 
    position: absolute; 
    top: 50px; 
    z-index: 1; 
} 
#ButtonVideo { 
    background-image: url('/media/Bt.png'); 
    width: 100px; 
    height: 30px; 
    position: absolute; 
    left: 105; 
    top: 50px; 
    z-index: 1; 
} 
#Footer { 
    border-top-width: 1px; 
    border-top-color: rgb(0,0,1); 
    border-top-style: solid; 
    width: 800px; 
    position: absolute; 
    bottom: 0; 
    z-index: 1; 
    text-align: center; 
} 
#Content { 
    position: absolute; 
    top: 90px; 
    width: 800px; 
    height: 95%; 
    border-top: 1px solid #000001; 
} 
#YouTubeBox { 
    position: absolute; 
    background-image: url('/media/Box.png'); 
    width: 100px; 
    height: 30; 
    left: 10px; 
    text-align: center; 
} 
#TwitterBox { 
    position: absolute; 
    background-image: url('/media/Box.png'); 
    width: 100px; 
    height: 30; 
    left: 110px; 
    text-align: center; 
} 
#FaceBookBox { 
    position: absolute; 
    background-image: url('/media/Box.png'); 
    width: 100px; 
    height: 30; 
    left: 210px; 
    text-align: center; 
} 
.DivT { line-height: 1px } 

HTMLコードDIV

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta name="generator" content= 
    "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" /> 

    <title>HTML CODE</title> 
    <meta name="description" content="Null" /> 
    <meta name="keywords" content="Null" /> 
    <link href="ThemeV1.css" rel="stylesheet" type="text/css" /> 
</head> 

<body background="/media/Background.png"> 
    <div id="Container"> 
    <!-- Start Container --> 

    <div id="LogoContainer"></div> 

    <div id="LikeBar"></div><!-- Menu Controls --> 

    <div id="ButtonHome"></div><!-- WEBSITE CONTENT --> 

    <div id="Content"> 
     <p class="DivT">We're upgrading the website with a new design and hopefully it will 
     be faster, so check back later.</p> 
    </div><!-- END WEBSITE CONTENT --> 
    <!-- Footer --> 

    <div id="Footer"></div><!-- End Footer --> 
    </div><!-- End Container --> 
</body> 
</html> 

だから、何が間違っていると?私は手動で高さを設定しないように時間を節約したい。

+10

誰かがあなたが投稿したCSSを読んで読んでくれると期待していますか?質問を投稿する際に読者を考慮してください。ヘルプは[こちら](http://jsbeautifier.org/)、[ここ](http://procssor.com/process)、[ここ](http://infohound.net/tidy/)です。 – Bojangles

+1

高さを変えよう:95%から最低高さ:95% – ptriek

+1

と[ここ](http://jsfiddle.net)! – MCSI

答えて

8

div#Contentは絶対にdiv#Containerに配置されているため、コンテナは独自の寸法を決定する際にコンテンツの高さと幅を無視します。 div#Contentpositionの値をrelativeとしてください。上記のコメントに記載されているように、そのheightプロパティをmin-heightに切り替えます。絶対位置を固定してコンテンツの影響を受ける高さが必要な場合は、コンテンツdivの高さが変更されたときにJavaScriptを使用して包含divのstyle.heightを調整する必要があります。

+0

これは私にとってはまったく正しいとは思われません。絶対的に配置された要素がそのコンテンツの幅や高さを無視しない限り、私は知っています。 – ptriek

+0

本当に正しいです。ただし、任意の位置を指定したブロック要素は、絶対配置された子の幅/高さを無視します。したがって、コンテンツdivがそのコンテンツに合わせて展開されても、それを囲むコンテナdivは表示されません。 – Aaron

3

あなたはが手動でコンテンツの高さの高さを設定しているように見えます:

#Content { 
... 
    height: 95%; 

heightを削除し、その高さは、その(非浮かべ)の内容を保持する必要があるものは何でもなります。

0

サイズを変更したい場合は、height属性を指定しないdivを自動的にサイズ変更し、その中に含まれるコンテンツの高さに合わせます。少なくともXXXpxの高さにしたい場合や、スクリーンに特定の方法でフィットさせたい場合は、min-height属性を使用してください。これは、テキストが小さすぎる場合は希望の領域に表示されるように高さを固定し、テキストが最小設定より大きい場合は拡大します。

あなたが、私はそれらのすべてに行くつもりはありませんが、私は最低でもこれらを調整することをここで説明したように多くの高さがあります。

#Container { min-heigh: 100%;} 
#Content { min-height: 95%; } 

*注 - 高さ分と分の幅をしていますIE6ではサポートされていません。

また、エレメントの配置は、標準のデータフローからエレメントを取り出すことができるため、高さに関して多くの問題を引き起こす可能性があります。何かをする必要がない限り、レイアウトを適切に設定すると、 Zインデックスを設定したり、サイトでスクロールする固定の背景を必要とするような特殊なものです。

関連する問題