1. 程式人生 > 其它 >編寫一個簡單的tomcat

編寫一個簡單的tomcat

方法一:給父元素增加height屬性

<style>
  #app {
    width: 1000px;
    height: 500px;
    background-color: red;
  }
  #child1 {
    width: 300px;
    height: 300px;
    background-color: blue;
    float: left;
  }
  #child2 {
    width: 300px;
    height: 300px;
    background-color: green;
    float: left;
  }
  .clear {
    clear: both;
  }
</style> <body> <div id="app"> <div id="child1"></div> <div id="child2"></div> </div> </body>

方法二:給父元素新增overflow:hidden屬性,注意此屬性對效果的影響

<style>
  #app {
    width: 1000px;
    background-color: red;
    overflow: hidden;
  }
  #child1 {
    width: 300px;
    height: 300px;
    background
-color: blue; float: left; } #child2 { width: 300px; height: 300px; background-color: green; float: left; } .clear { clear: both; } </style> <body> <div id="app"> <div id="child1"></div> <div id="child2"></div> </div> </body>

方法三:浮動元素後面增加一個元素,設定clear:both屬性

<style>
  #app {
    width: 1000px;
    background-color: red;
    overflow: hidden;
  }
  #child1 {
    width: 300px;
    height: 300px;
    background-color: blue;
    float: left;
  }
  #child2 {
    width: 300px;
    height: 300px;
    background-color: green;
    float: left;
  }
  .clear {
    clear: both;
  }
</style>
<body>
  <div id="app">
    <div id="child1"></div>
    <div id="child2"></div>
    <div class="clear"></div>
  </div>
</body>

方法四:使用after偽類清浮動

#app {
    width: 1000px;
    background-color: red;
  }
  #child1 {
    width: 300px;
    height: 300px;
    background-color: blue;
    float: left;
  }
  #child2 {
    width: 300px;
    height: 300px;
    background-color: green;
    float: left;
  }
  .clearfix:after {
    content: ' ';
    display: block;
    height: 0px;
    clear: both;
    visibility: hidden;
  }
  .clearfix {
      zoom: 1;    /* ie6-ie7執行,其他瀏覽器不執行 */
  }
</style>
<body>
  <div id="app" class="clearfix">
    <div id="child1"></div>
    <div id="child2"></div>
  </div>
</body>

方法五:使用after和before雙偽類

<style>
  #app {
    width: 1000px;
    background-color: red;
  }
  #child1 {
    width: 300px;
    height: 300px;
    background-color: blue;
    float: left;
  }
  #child2 {
    width: 300px;
    height: 300px;
    background-color: green;
    float: left;
  }
  .clearfix:after, .clearfix:before {
    content: ' ';
    display: table;
  }
  .clearfix:after {
    clear: both;
  }
  .clearfix {
      zoom: 1;    /* ie6-ie7執行,其他瀏覽器不執行 */
  }
</style>
<body>
  <div id="app" class="clearfix">
    <div id="child1"></div>
    <div id="child2"></div>
  </div>
</body>