css - 按高度将页面分成多个部分,部分未扩展到指定的完整高度

标签 css twitter-bootstrap

下面是我的代码。我把整个页面按高度划分,20%、50%、30%;

但是由于某些原因,SECOND SECTION 中的表没有得到全部 50%。也许只有10%。它驻留在行流体中。如果我 overflow hidden ,则只有标题可见。

CSS:

  .body-wrapper{
    height:100%;
  }
  .body-wrapper > fieldset div:nth-of-type(1){
    height:20%;
  }
  .body-wrapper > fieldset div:nth-of-type(2){
    height:40%;
  }
  .body-wrapper > fieldset div:nth-of-type(3){
    height:30%;
  }

html:

    <div class = "main-Frame container-fluid"> <!-- mid section -->
      <div class="well row-fluid" >
        <div class="body-wrapper">
          <fieldset>

            <div> <!-- FIRST SECTION -->
              <legend>User Profile</legend>
              <div class="row-fluid">
                <div class="col-md-2 text-right">User Name
                </div>
                <div class="col-md-4" >
                  <input style="width:90%;"type="text" placeholder="username"/>
                </div>
                <div class="col-md-2 text-right">User Email
                </div>
                <div class="col-md-3">kkk@gmail.com
                </div>
                <div class="col-md-1">
                  <input type="checkbox"/>Active
                </div>
              </div>
            </div> <!-- END OF FIRST SECTION -->

            <div> <!-- SECOND SECTION -->
              <legend>Application Defaults</legend>
              <div class = "container-fluid" style="height:100%;">
                <div class="row-fluid"  style="height:100%;">
                  <div class="col-md-10" style="height:100%;">
                    <div class="table-responsive user-table">

                    <table class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th>App</th>
                          <th>Type</th>
                          <th>Setting</th>
                          <th>check</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr>
                          <td>first</td>
                          <td>first</td>
                          <td>first</td>
                          <td>first</td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </div>

                  <div class="col-md-2">
                  </div>
                </div>
              </div>

            </div> <!-- END of SECOND section -->


            <div> <!-- LAST section -->
              <legend>ChangePassword</legend>
            </div> <!-- END of footer section -->

          </fieldset>
        </div>

最佳答案

这里的问题是您的 CSS 选择器太宽泛了 - 选择器 .body-wrapper > fieldset div:nth-of-type(1)匹配既定目标(第一个 <div> 直接在字段集下,嵌套更深的 <div class="table-responsive user-table"> 。(在前面所有也匹配的元素上,您使用内联样式将它们的高度强制为 100%,因此它们不要表现出相同的问题行为。)

要解决此问题,只需通过增加选择器的特异性来缩小选择器匹配的元素范围 - 例如,仅定位直接子元素 <div>字段集下的元素,而不是所有后代元素:

.body-wrapper {
  height: 100%;
}
.body-wrapper > fieldset > div:nth-of-type(1) {
  height: 20%;
}
.body-wrapper > fieldset > div:nth-of-type(2) {
  height: 40%;
}
.body-wrapper > fieldset > div:nth-of-type(3) {
  height: 30%;
}

希望对您有所帮助!如果您有任何问题,请告诉我。

关于css - 按高度将页面分成多个部分,部分未扩展到指定的完整高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37685200/

相关文章:

javascript - 为什么主线程上的同步 XMLHttpRequest 的 ajax 调用给出错误已被弃用?

jquery - 光滑的旋转木马。想要自动播放幻灯片一次并停止

html - css负边框形状

javascript - Scrollspy 不工作 Bootstrap 4

javascript - Bootstrap标签输入不适用于本地数据

javascript - 如何使用 Ajax 通过 Bootstrap Modal 提交表单

php - 定位 Twitter Bootstrap 警告框时出错。

javascript - 如何使 div 成为设备屏幕高度 css 的 10%

javascript - 如何通过 Bootstrap 在弹出按钮中制作内容文本 "rtl"

html - 无论如何如何悬停整个元素