2016-11-02 2 views
1

У меня есть класс контейнера. Внутри этого класса все мои элементы. Включая вертикальную панель (link-panel) и div рядом с ней (control_panel). Я пытаюсь дать свою вертикальную высоту бара: 100%. Я знаю, что я должен предоставить классу контейнера высоту 100% для его работы, но каждый раз, когда я пытаюсь сделать, div (control_panel) работает поверх нижнего колонтитула (элемент, который не находится в контейнере). Я сделал jsfiddle того, что испытываю, но учтите, что нижний колонтитул в реальном файле динамически добавляется в HTML, поэтому я не включил его в свой контейнерный класс.)Давление вертикальной высоты бара 100%

Я также попытался дать высоту тела 100%, но тело не отражает никаких изменений в вертикальной полосе, потому что родитель вертикальной полосы является контейнером. Как сделать так, чтобы я мог достичь вертикальной полосы со 100% высотой, которая заканчивается до нижнего колонтитула? Here's my jsFiddle

.container { 
 
    display: block; 
 
    margin: 0px auto; 
 
    width: 100%; 
 
} 
 
.footer { 
 
    display: block; 
 
    width: 100%; 
 
    height: 500px; 
 
    background-color: black; 
 
    margin-top: 0px; 
 
} 
 
html, 
 
body { 
 
    position: relative; 
 
    height: 100%; 
 
    background-color: #f2f2f2; 
 
} 
 
.control_panel { 
 
    position: relative; 
 
    display: inline-block; 
 
    width: 60%; 
 
    margin-left: 0px; 
 
} 
 
.control_title { 
 
    display: block; 
 
    background-color: white; 
 
    height: 100px; 
 
    margin-bottom: 30px; 
 
} 
 
.control_settings { 
 
    display: block; 
 
    background-color: white; 
 
    height: 900px; 
 
    width: 900px; 
 
} 
 
.link-panel { 
 
    position: relative; 
 
    float: left; 
 
    width: 30%; 
 
    height: 100%; 
 
    background-color: #333333; 
 
} 
 
.link-panel ul { 
 
    list-style-type: none; 
 
    font-size: 19px; 
 
    margin-top: 35px; 
 
} 
 
.link-panel li { 
 
    margin-top: 15px; 
 
}
<html> 
 

 
<body> 
 
    <div class="container"> 
 

 
    <div class='control_panel'> 
 
     <div class='control_title'> 
 
     <h2>Your Settings</h2> 
 
     </div> 
 

 
     <div class='control_settings'> 
 

 
     </div> 
 
    </div> 
 

 
    <div class="link-panel"> 
 
     <ul> 
 

 

 
     <li>Dashboard</li> 
 
     <hr> 
 
     <li>Blog</li> 
 
     <hr> 
 
     <li><span><b>|</b> Settings</span> 
 
     </li> 
 
     <hr> 
 
     <li>Contact Us</li> 
 

 

 
     </ul> 
 
    </div> 
 
    <!--End of link panel div--> 
 
    </div> 
 

 
    <div class='footer'> 
 

 
    </div> 
 
</body> 
 

 
</html>

+0

Что делать, если вы назначаете 'цвет фона: # 333333;' в '.container'? – Banzay

ответ

1

Вы хотите ребенка ДИВ быть высотой 100% или их соответствующим родительским DIV, то вы можете использовать позиции для достижения этой цели.

Просмотреть обновленную скрипку.

.container { 
    display: block; 
    margin: 0px auto; 
    width: 100%; 
    padding-left:30%; 
    box-sizing:border-box; 
    position:relative; 
} 
.link-panel { 
    position: absolute; 
    float: left; 
    width: 30%; 
    height: 100%; 
    background-color: #333333; 
    left: 0; 
    top: 0; 
} 

+0

Это именно то, что я хотел. Спасибо! – user2896120

1

.container { 
 
    display: block; 
 
    margin: 0px auto; 
 
    width: 100%; 
 
} 
 
.footer { 
 
    display: block; 
 
    width: 100%; 
 
    height: 500px; 
 
    background-color: black; 
 
    margin-top: 0px; 
 
} 
 
html, 
 
body { 
 
    position: relative; 
 
    height: 100%; 
 
    background-color: #f2f2f2; 
 
} 
 
.control_panel { 
 
    position: relative; 
 
    display: inline-block; 
 
    width: 60%; 
 
    height: 100%; // A CHANGE HERE 
 
    margin-left: 0px; 
 
} 
 
.control_title { 
 
    display: block; 
 
    background-color: white; 
 
    height: 100px; 
 
    margin-bottom: 30px; 
 
} 
 
.control_settings { 
 
    display: block; 
 
    background-color: white; 
 
    width: 900px; // REMOVED HEIGHT HERE 
 
} 
 
.link-panel { 
 
    position: relative; 
 
    float: left; 
 
    width: 30%; 
 
    height: 100%; 
 
    background-color: #333333; 
 
} 
 
.link-panel ul { 
 
    list-style-type: none; 
 
    font-size: 19px; 
 
    margin-top: 35px; 
 
} 
 
.link-panel li { 
 
    margin-top: 15px; 
 
}
<!-- Code order changed ---> 
 
<div class="container"> 
 
    <div class="link-panel"> 
 
    <ul> 
 
     <li>Dashboard</li> 
 
     <hr> 
 
     <li>Blog</li> 
 
     <hr> 
 
     <li><span><b>|</b> Settings</span> 
 
     </li> 
 
     <hr> 
 
     <li>Contact Us</li> 
 
    </ul> 
 
    </div> 
 
    <!--End of link panel div--> 
 
    <div class='control_panel'> 
 
    <div class='control_title'> 
 
     <h2>Your Settings</h2> 
 
    </div> 
 
    <div class='control_settings'> 
 
    </div> 
 
    </div> 
 
</div> 
 
<div class='footer'></div>

+0

Это не работает, когда я начинаю добавлять контент в control_settings. Высота control_panel становится больше, чем высота панели ссылки. Я хочу, чтобы высота панели ссылок всегда составляла 100% страницы. – user2896120

+0

Вам нужна липкая правая боковая панель? –

+0

Да, правая панель не должна двигаться со своего места – user2896120

0
<html> 
<head> 
<style> 
html, body { 
    position: relative; 
    height: 100%; 
    background-color: #f2f2f2; 
} 
.left-container { 
    width: 30%; 
    position: fixed; 
    height: 100%; 
    left: 0; 
    top: 0; 
} 
.link-panel { 
    position: relative; 
    float: left; 
    width: 100%; 
    height: 100%; 
    background-color: #333333; 
} 
.link-panel ul { 
    list-style-type: none; 
    font-size: 19px; 
    margin-top: 35px; 
} 

.link-panel li { 
    margin-top: 15px; 
} 
.right-container { 
    width: 70%; 
    margin-left: 30%; 
    clear: right; 
    display: block; 
    height: 100%; 
} 
.control_panel { 
    position: relative; 
    display: inline-block; 
    width: 100%; 
    margin-left: 0px; 
} 
.control_title { 
    display: block; 
    background-color: white; 
    height: 50px; 
} 
h2 { 
    display: block; 
    font-size: 1.5em; 
    -webkit-margin-before: 0.83em; 
    -webkit-margin-after: 0.83em; 
    -webkit-margin-start: 0px; 
    -webkit-margin-end: 0px; 
    font-weight: bold; 
} 
.control_settings { 
    display: block; 
    background-color: white; 
    width: 100%; 
} 
.footer { 
    display: block; 
    width: 100%; 
    height: 500px; 
    background-color: black; 
    margin-top: 0px; 
    position: fixed; 
    top: 90%; 
    left: 0; 
} 
</style> 
</head> 
<body> 
    <div class="left-container"> 
     <div class="link-panel"> 
     <ul> 
     <li> Dashboard</li> 
      <hr> 
      <li> Blog</li> 
      <hr> 
      <li><span><b>|</b> Settings</span></li> 
      <hr> 
      <li> Contact Us</li> 
     </ul> 
     </div> 
    </div> 
     <!--End of link panel div--> 
     <div class="right-container"> 
     <div class='control_panel'> 
     <div class='control_title'> 
      <h2>Your Settings</h2> 
     </div> 
    </div> 

     <div class='control_settings'>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. 
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. 
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. 
</div> 
    </div> 

    <div class='footer'> 

    </div> 
    </body> 
</html> 
Смежные вопросы