2010-10-15 3 views
1

Я использую превосходный пример peter для высоты 100% высоты с липким нижним колонтитулом (HERE). Я пропустил части нижнего колонтитула, я не использую его.ребенок div высота 100% игнорируется

Однако, когда я использую дочерний div и пытаюсь сделать то же самое, он не работает. Я хочу, чтобы дочерний div также принимал 100% высоты своего родителя. Вот CSS:

<style> 


    html,body { 
     margin:0; 
     padding:0; 
     height:100%; /* needed for container min-height */ 
     background:gray; 

     font-family:arial,sans-serif; 
     font-size:small; 
     color:#666; 
    } 



    div#container { 
     position:relative; /* needed for footer positioning*/ 
     margin:0 auto; /* center, not in IE5 */ 
     width:750px; 
     background:#f0f0f0; 

     height:auto !important; /* real browsers */ 
     height:100%; /* IE6: treaded as min-height*/ 

     min-height:100%; /* real browsers */ 
    } 

    div#header { 
     padding:1em; 
     background:#ddd url("../csslayout.gif") 98% 10px no-repeat; 
     border-bottom:6px double gray; 
    } 


    div#content { 
     padding:1em 1em 5em; /* bottom padding for footer */ 
     position:relative; /* needed for footer positioning*/ 
     margin:0 auto; /* center, not in IE5 */ 

     height:auto !important; /* real browsers */ 
     height:100%; /* IE6: treaded as min-height*/ 

     min-height:100%; /* real browsers */    
    } 
    div#content_subdiv{ 
     padding:1em 1em 5em; /* bottom padding for footer */ 
     background:#999; 
     height:100%; 

     color:#fff; 
    } 


</style> 

и вот мой HTML код:

<div id="container"> 

    <div id="header"> 
     <h1>CSS layout: 100% height with header and footer</h1> 
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget massa dolor, rhoncus tempor nunc. Donec tempor odio eget purus vehicula auctor. </p> 
    </div> 

    <div id="content"> 

     <p> 
    Aenean quam mauris, iaculis non aliquet quis, facilisis sed turpis. Cras id erat velit, nec bibendum erat. Vivamus feugiat purus vitae velit dictum in vestibulum ante tristique. Vestibulum ut massa vel justo eleifend consectetur eget ut nisi. Phasellus ut diam nulla. Suspendisse potenti. Praesent blandit gravida facilisis. Donec elementum faucibus gravida. Nullam nec enim velit, ac scelerisque justo. Pellentesque lacus metus, adipiscing nec congue a, volutpat sollicitudin eros. Donec tortor leo, tempor non viverra at, molestie sed dui. Nullam ipsum purus, tempus elementum tincidunt id, iaculis at lectus. Vestibulum viverra mi in mauris ultrices sollicitudin 
     </p> 
     <div id="content_subdiv"> this sub div not stretching to 100%; <br /> this sub div not stretching to 100%; <br /> this sub div not stretching to 100%; <br /> this sub div not stretching to 100%; <br /> this sub div not stretching to 100%; <br /></div> 
    </div> 

</div> 
+3

Для тех людей, которые говорят, что «Все, что вы можете сделать с помощью таблиц можно сделать с помощью CSS», то решить этот вопрос. Else, я собираюсь использовать большую тучную таблицу в своем HTML для целей макета. – capdragon

+0

@capdragon Вы хотите, чтобы ребенок DIV принимал 100% от высоты родителя? Но как насчет абзаца, который также находится внутри родителя? Абзац занимает некоторое вертикальное пространство, поэтому ребенок DIV не может взять всех 100% высоты родителей ... –

+0

@Sime Подраздел должен занимать оставшееся пространство – capdragon

ответ

0

Хорошо, я не вижу свой CSS для #content_subdiv в вопросе ...?

+0

попробуйте прокрутку в блоке кода? – capdragon

+0

Извините, слепой. Моя вина. Если вы задаете определенное значение в высоте содержимого div #, значит, #content_subdiv будет отображаться так, как ожидалось? –

+0

Хорошо, уступил любопытству и создал страницу, используя вашу разметку. Какое желаемое поведение? Используя то, что у вас там, ваш контент div # установлен на расчетную высоту области просмотра, но div # content_subdiv пытается получить 100% этого значения. Проблема заключается в том, что добавление div # content_subdiv фактически увеличивает высоту окна просмотра по высоте содержимого #viewport_subdiv, поэтому его нельзя фактически вычислить. Я думаю. –

0

Вы можете применить минимальную высоту: 100% к первому элементу тела.

Поместите заголовок внутри содержимого div или создайте минимальную высоту: 100% обертка div.

+0

У меня есть min-height: 100% -ный оберточный div, называемый «div # container». – capdragon

0

Попробуйте этот код, то:

html,body { 
    margin:0; 
    padding:0; 
    height:100%; /* needed for container min-height */ 
    background:gray ; 
    font-family:arial,sans-serif; 
    font-size:small; 
    color:#666; 
} 



div#container { 
    position:relative; /* needed for footer positioning*/ 
    margin:0 auto; /* center, not in IE5 */ 
    width:750px; 
    background:#f0f0f0; 

    height:auto !important; /* real browsers */ 
    height:100%; /* IE6: treaded as min-height*/ 

    min-height:100%; /* real browsers */ 
} 

div#header { 
    padding:1em; 
    background:#ddd url("../csslayout.gif") 98% 10px no-repeat; 
    border-bottom:6px double gray; 
} 


div#content { 
    padding:1em 1em 5em; /* bottom padding for footer */ 
    position:relative; /* needed for footer positioning*/ 
    margin:0 auto; /* center, not in IE5 */ 

    height:auto !important; /* real browsers */ 
    height:100%; /* IE6: treaded as min-height*/ 

    min-height:100%; /* real browsers */    
} 
div#content_subdiv{ 
    padding:1em 1em 5em; /* bottom padding for footer */ 
    background:#999; 
    color:#fff; } 
< div id="header "> 
    <h1>CSS layout: 100% height with header and footer</ h1 > 
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget massa dolor, rhoncus tempor nunc. Donec tempor odio eget purus vehicula auctor. </p> 
</div> 

<div id="content"> 

    <p> 
Aenean quam mauris, iaculis non aliquet quis, facilisis sed turpis. Cras id erat velit, nec bibendum erat. Vivamus feugiat purus vitae velit dictum in vestibulum ante tristique. Vestibulum ut massa vel justo eleifend consectetur eget ut nisi. Phasellus ut diam nulla. Suspendisse potenti. Praesent blandit gravida facilisis. Donec elementum faucibus gravida. Nullam nec enim velit, ac scelerisque justo. Pellentesque lacus metus, adipiscing nec congue a, volutpat sollicitudin eros. Donec tortor leo, tempor non viverra at, molestie sed dui. Nullam ipsum purus, tempus elementum tincidunt id, iaculis at lectus. Vestibulum viverra mi in mauris ultrices sollicitudin 
    </p> 

</div> <div id="content_subdiv"> this sub div not stretching to 100%; <br /> this sub div not stretching to 100%; <br /> this sub div not stretching to 100%; <br /> this sub div not stretching to 100%; <br /> this sub div not stretching to 100%; <br /></div> 

+0

близко, но нет сигары. То, что делает этот код, делает действие #content_subdiv как нижний колонтитул и растягивает содержимое. – capdragon

Смежные вопросы