【问题标题】:Giving a vertical bar height 100%给垂直条高度 100%
【发布时间】:2016-11-02 16:22:09
【问题描述】:

我有一个容器类。在那个类里面是我所有的元素。包括竖线(链接面板)和它旁边的 div(控制面板)。我试图给我的垂直条高度:100%。我知道我必须为容器类提供 100% 的高度才能使其工作,但每次我尝试这样做时,(control_panel) div 都会在页脚(不在容器中的元素)之上运行。我已经对我正在经历的事情做了一个 jsfiddle,但请注意,真实文件中的页脚是动态添加到 HTML 中的,所以这就是我没有将它包含在我的容器类中的原因。)

我也尝试将主体高度设置为 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>

【问题讨论】:

  • 如果将background-color: #333333; 分配给.container 会怎样?

标签: html css


【解决方案1】:

您希望子 div 具有 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;
}

https://jsfiddle.net/pd5bLv63/3/

【讨论】:

  • 这正是我想要的。谢谢!
【解决方案2】:

.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>

【讨论】:

  • 当我开始向 control_settings 添加内容时,这不起作用。 control_panel 的高度变得大于链接面板的高度。我希望链接面板的高度始终为页面的 100%。
  • 是的,右侧面板不应该从它的位置移动
【解决方案3】:
 <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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-23
    • 2012-02-26
    • 1970-01-01
    • 2017-03-24
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    相关资源
    最近更新 更多