zoukankan      html  css  js  c++  java
  • CSS中的盒子模型详解

    很多人对盒子模型搞晕头了,下面通过一个简单的代码来分析盒子模型的结构!

    为了方便方便观看!在第一个div中画了一个表格,并将其尺寸设置成与div内容大小一样!且设置body的margin和padding的属性都为0px;

    本例子采用行内CSS样式!

    代码如下:

    <!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=utf-8" />
    <title>盒子模型</title>
    </head>
    
    <body style="margin:0px; padding:0px;">
    <div style="900px; height::auto">
      <div style="900px; height:100px; background-color:#021; color:#FFF; padding:25px; margin:25px;border: 50px solid #0CF; ">
        <table width="900px" height="100px" border="1" cellspacing="0" cellpadding="0" bordercolor="#FF0000">
          <tr >
            <td style="text-align:center; font-size:36px;">Javalittleman</td>
          </tr>
        </table>
      </div>
      <div style="30%; height:120px; float:left; background-color:#063; border-color:#039;"></div>
      <div style="70%; height:120px;float:left; background-color:#123;"></div>
      <div style="900px; height:120px;float:left; background-color:#111;"></div>
    </div>
    </body>
    </html>
    

    把标尺打开!

    大家发现了什么没有?

    QQ截图20141119131234

    分析如下:

    显示效果:

    image

    其它设置的table是固定不变的,也就是说内容大小都不会改变的,改变的只是位置!

    border:是边框,向外扩张,并可以为其添加颜色属性

    margin:是向外扩张,没有颜色属性,所以我们看到扩张后的颜色是外部的颜色,在本例子中是无色的!

    padding:是向内填充的,没有颜色属性,显示的颜色是内部内容设置的颜色!

  • 相关阅读:
    跳出iframe
    leetcode 225. Implement Stack using Queues
    leetcode 206. Reverse Linked List
    leetcode 205. Isomorphic Strings
    leetcode 203. Remove Linked List Elements
    leetcode 198. House Robber
    leetcode 190. Reverse Bits
    leetcode leetcode 783. Minimum Distance Between BST Nodes
    leetcode 202. Happy Number
    leetcode 389. Find the Difference
  • 原文地址:https://www.cnblogs.com/javalittleman/p/4108092.html
Copyright © 2011-2022 走看看