CSS中的盒子模型详解

WBOY
Release: 2016-05-25 18:02:29
Original
1708 people have browsed it

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

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

本例子采用行内CSS样式!

代码如下:

    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>盒子模型</title>
 
<div style="width:900px; height::auto"></div> <div class="line number10 index9 alt1"> <code class="text spaces">  <div style="width:900px; height:100px; color:#FFF; padding:25px; margin:25px;border: 50px solid #0CF; "></div> <div class="line number11 index10 alt2"> <code class="text spaces">    <table width="900px" height="100px" border="1" cellspacing="0" cellpadding="0" bordercolor="#FF0000"> <div class="line number12 index11 alt1"> <code class="text spaces">      <tr> <div class="line number13 index12 alt2"> <code class="text spaces">        <td style="text-align:center; font-size:36px;">Javalittleman</td>
      
  
  <div style="width:30%; height:120px; float:left; border-color:#039;"></div>
  <div style="width:70%; height:120px;float:left; "></div>
  <div style="width:900px; height:120px;float:left; "></div>

把标尺打开!

大家发现了什么没有?

QQ截图20141119131234

 

分析如下:

 

 

显示效果:

 

image

 

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

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

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

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

Related labels:
source:php.cn
Previous article:CSS3颜色特征温故 Next article:CSS- 文本超出指定宽度后隐藏并显示为省略号
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template