“盒子的嵌套布局(二)”的版本间的差异

来自CloudWiki
跳转至: 导航搜索
盒子嵌套的分类
第2行: 第2行:
 
=== 嵌套元素竖直排列 ===
 
=== 嵌套元素竖直排列 ===
 
*这种情况下最简单,
 
*这种情况下最简单,
 +
*[[文件:w3-47.png]]
 +
*源代码:
 +
    <nowiki><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 +
<html xmlns="http://www.w3.org/1999/xhtml">
 +
    <head>
 +
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 +
      <title>无标题文档</title>
 +
      <style type="text/css">
 +
          *{margin:0;padding:0;}
  
 +
          .layer2{width:100%; height:200px;}
 +
 
 +
          .layer2-1{width:100%; height:100px; background:red;text-align:center;} 
 +
          .layer2-2{width:100%; height:100px; background:orange;text-align:center;}
 +
      </style>
 +
    </head>
 +
    <body>
 +
 +
      <div class="layer2">
 +
            <div class="layer2-1"><h2>盒子2-1</h2></div>
 +
            <div class="layer2-2"><h2>盒子2-2</h2></div>
 +
 +
      </div>   
 +
 +
    </body>
 +
</html></nowiki>
 
=== 嵌套元素竖直排列 ===
 
=== 嵌套元素竖直排列 ===
 
*这种情况稍微复杂一点
 
*这种情况稍微复杂一点
 +
*[[文件:w3-46.png]]
 +
*源代码:
 +
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 +
<nowiki><html xmlns="http://www.w3.org/1999/xhtml">
 +
    <head>
 +
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 +
      <title>无标题文档</title>
 +
      <style type="text/css">
 +
          *{margin:0;padding:0;}
 +
 +
          .layer2{width:100%; height:200px;}
 +
 
 +
          .layer2-1{width:40%; height:160px; background:red;text-align:center;float:left;} 
 +
          .layer2-2{width:60%; height:160px; background:orange;text-align:center;float:left;m}
 +
          .layer2-3{clear:both;} 
 +
 +
      </style>
 +
    </head>
 +
    <body>
  
 +
      <div class="layer2">
 +
            <div class="layer2-1"><h2>盒子2-1</h2></div>
 +
            <div class="layer2-2"><h2>盒子2-2</h2></div>
 +
            <div class="layer2-3"></div>
 +
      </div>   
  
 +
    </body>
 +
</html></nowiki>
  
 
== 高度塌陷 ==
 
== 高度塌陷 ==

2017年11月4日 (六) 14:04的版本

盒子嵌套的分类

嵌套元素竖直排列

  • 这种情况下最简单,
  • W3-47.png
  • 源代码:
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
       <title>无标题文档</title>
       <style type="text/css">
          *{margin:0;padding:0;}

           .layer2{width:100%; height:200px;}
  
           .layer2-1{width:100%; height:100px; background:red;text-align:center;}  
           .layer2-2{width:100%; height:100px; background:orange;text-align:center;} 
       </style>
    </head>
    <body>

       <div class="layer2">
            <div class="layer2-1"><h2>盒子2-1</h2></div>
            <div class="layer2-2"><h2>盒子2-2</h2></div>

       </div>    

    </body>
 </html>

嵌套元素竖直排列

  • 这种情况稍微复杂一点
  • W3-46.png
  • 源代码:
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
       <title>无标题文档</title>
       <style type="text/css">
          *{margin:0;padding:0;}

           .layer2{width:100%; height:200px;}
  
           .layer2-1{width:40%; height:160px; background:red;text-align:center;float:left;}  
           .layer2-2{width:60%; height:160px; background:orange;text-align:center;float:left;m} 
           .layer2-3{clear:both;}   

       </style>
    </head>
    <body>

       <div class="layer2">
            <div class="layer2-1"><h2>盒子2-1</h2></div>
            <div class="layer2-2"><h2>盒子2-2</h2></div>
            <div class="layer2-3"></div>
       </div>    

    </body>
 </html>

高度塌陷