如何防止表高度溢出容器div?

时间:2016-07-03 00:01:03

标签: html css layout html-table css-tables

我需要将表包含在其容器div中。

造型宽度完美,但高度完全没有反应。

我搜索过几十个类似的帖子。我已经尝试了表格布局:固定,相对定位容器,最大/最小高度,似乎没有任何工作。

    <!DOCTYPE html>
<html>

  <head>
    <title> Aisha-Flix </title>
    <script src="https://code.jquery.com/jquery.min.js"></script>
    <link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" type="text/css" />
    <script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Prompt:300,600" rel="stylesheet"> 

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">




    <style>

    html{height:100%}

    body{
      padding: 0;
      margin: 0;
      color: #f5f5f5;
      font-family: 'Prompt', sans-serif;
      height: 100%;
    }


    #content{
      height: 100vh;
      border: 1px solid black;
      position: relative;
      background-color: black;

    }

    #movieContainer{
      position: absolute;
      width: 100%;
      height: 50vh;
      top: 33vh;
      background: url(giphy3.gif);
      background-size: 100% 100%;
      border: 1px solid green;
    }

    table{
      width: 100%;
      height: 90%;
      border: 1px solid red;
      table-layout: fixed;

    }

    #number{
      font-size: 16vh;
      padding-top: 16vh;

    }

    #number span{
      font-size: 30vh;
      font-family: Gill Sans;
    }

    td{
      border: 1px solid orange;
    }

    .anim{
      background: url(static.gif) !important;
      background-size: cover !important;
      background-repeat: no-repeat;

    }

    td:nth-child(2){
      vertical-align: top;
    }

    p:first-child{
      font-family: Gill Sans;
      font-size: 1.7em;
    }

    #rating{
      text-align: right;
      vertical-align: top;
    }




    </style>
  </head>

  <body>

    <div id="content">
      <button id="test"> </button>

      <div class="col-xs-12" id="movieContainer">
        <table>
               <tr>
          <td id="number" width="66%" rowspan="2">#<span>7</span></td>
          <td>
            <p> 2001: A Space Odyssey</p>
            <p><b>Director</b></p>
            <p style="margin-top: -10px;"> Stanley Kubrick - 1968</p>
            <p><b>DP </b></p>
            <p style="margin-top: -10px;"> Geoffrey Unsworth </p>
          </td>
        </tr> 

            <tr> <td id="rating"> <p> &#11088 &#11088 &#11088 </p></td></tr>

        </table>
      </div>

      <div id="addMovie"></div>
    </div>

    <div id="footer"> </div>


     <script type="text/javascript">

        var windowHeight =  $(window).height();

        $("#landingPage").height(windowHeight + "px"); 

        $("#test").click(function(){
          $("#movieContainer").addClass("anim");
        });




      </script>


  </body>


</html>

JSBIN:http://output.jsbin.com/zafodepozu

1 个答案:

答案 0 :(得分:0)

问题正在发生,因为div .movi​​eContainer具有固定的高度 如果将其高度更改为auto,它将起作用

&#13;
&#13;
    var windowHeight = $(window).height();

    $("#landingPage").height(windowHeight + "px");

    $("#test").click(function() {
      $("#movieContainer").addClass("anim");
    });
&#13;
    html {
      height: 100%
    }
    
    body {
      padding: 0;
      margin: 0;
      color: #f5f5f5;
      font-family: 'Prompt', sans-serif;   height: 100%;
    }
    
    #content {
      height: 100vh;
      border: 1px solid black;
      position: relative;
      background-color: black;
    }
    
    #movieContainer {
      position: absolute;
      width: 100%;
      height: auto;
      top: 33vh;
      background: url(giphy3.gif);
      background-size: 100% 100%;
      border: 1px solid green;
    }
    
    table {
      width: 100%;
      height: 90%;
      border: 1px solid red;
      table-layout: fixed;
    }
    
    #number {
      font-size: 16vh;
      padding-top: 16vh;
    }
    
    #number span {
      font-size: 30vh;
      font-family: Gill Sans;
    }
    
    td {
      border: 1px solid orange;
    }
    
    .anim {
      background: url(static.gif) !important;
      background-size: cover !important;
      background-repeat: no-repeat;
    }
    
    td:nth-child(2) {
      vertical-align: top;
    }
    
    p:first-child {
      font-family: Gill Sans;
      font-size: 1.7em;
    }
    
    #rating {
      text-align: right;
      vertical-align: top;
    }
&#13;
  <script src="https://code.jquery.com/jquery.min.js"></script>
  <link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" type="text/css" />
  <script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

  <!-- Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Prompt:300,600" rel="stylesheet">
 





<body>

  <div id="content">
    <button id="test"> </button>

    <div class="col-xs-12" id="movieContainer">
      <table>
        <tr>
          <td id="number" width="66%" rowspan="2">#<span>7</span></td>
          <td>
            dgdsgdsg
          </td>
        </tr>

        <tr>
          <td id="rating">
             &#11088 &#11088 &#11088
          </td>
        </tr>

      </table>
    </div>

    <div id="addMovie"></div>
  </div>

  <div id="footer"> </div>


 

 
&#13;
&#13;
&#13;