table布局 | div布局优势 |
浏览器支持完善 | |
表现和结构分离 | |
样式设计控制功能强大 | |
可以继承,层叠处理 |
"<input/>"
"<input>"即可
px : 像素 |
em : 当前对象体内的字体尺寸(好像英文比较常用这个尺寸) |
ex : 当前字符高度的相对尺寸 ( font-size:1.2ex,当前字符的1.2倍高) |
pt : 点/镑point (font-size:9pt;) |
pc : 派卡 pica |
in : 英寸 |
pc : 派卡 pica |
mm : 毫米 |
cm :厘米 |
rgb : (0,0,0) |
rgba:(0,0,0,0.2) |
rrggbb :十六进制的颜色单位 #ffffff; |
colorName : 字体颜色(color:blue) |
样式分有三种 :
/固定宽度的布局/
/流式布局(按照%比)/
/弹性布局,根据字体 em进行布局/
1:一列自适应: width:80%;
<h5>一列固定居中: margin:0 auto;</h5> <h5>二列固定宽度:</h5> <div id="two-row" class="clearFix"> <style> .clearFix:after{ content:""; display:block; visibility:visible; clear:both; height:0; } #two-row { width:500px; background:#666 } #two-row .left{ width:200px; background:#0C9; float:left; } #two-row .right{ width:300px; background:#069; float:left; } </style> <div class="left">row1</div> <div class="right">row2</div> </div>
2:两列宽度自适应:利用左右定位;中间居中
<div id="two-auto" class="clearFix"> <style> .clearFix:after{ content:""; display:block; visibility:visible; clear:both; height:0; } #two-auto { background:#666 } #two-auto .left{ width:35%; background:#0C9; float:left; } #two-auto .right{ width:30%; background:#069; float:left; } </style> <div class="left">auto-left</div> <div class="right">auto-right</div> </div>
3:两列右列宽度自适应
<div id="right-auto"> <style> #right-auto{ } #right-auto .left{ width:100px; float:left; background:#ccc; } #right-auto .right{ background:#f00; border:2px solid #000; } </style> <div class="left">left</div> <div class="right">right</div> </div>
<h5>三列自适应</h5> <div id="three"> <style> #three{ position:relative; } #three .left{ position:absolute; left:0;top:0; width:100px; height:300px; background:#C99; } #three .right{ position:absolute; top:0;right:0; width:100px; height:300px; background:#C99; } #three .center{ margin-left:100px; margin-right:100px; height:300px; background:#F03; } </style> <div class="left">left</div> <div class="right">right</div> <div class="center">center</div> </div>
<h5>三列自适应;利用左右浮动;中间居中</h5> <div id="three-1"> <style> #three-1{ position:relative; } #three-1 .left{ float:left; width:100px; height:300px; background:#C99; } #three-1 .right{ float:right; width:100px; height:300px; background:#C99; } #three-1 .center{ margin-left:100px; margin-right:100px; height:300px; background:#F03; } </style> <div class="left">left</div> <div class="right">right</div> <div class="center">center</div> </div>