想知道这种行为的原因.
CSS
div {
display: inline-block;
margin-right: 2px;
width: 20px;
background-color: red;
}
Run Code Online (Sandbox Code Playgroud)
空div
<div style="height:20px;"></div>
<div style="height:40px;"></div>
<div style="height:60px;"></div>
<div style="height:80px;"></div>
Run Code Online (Sandbox Code Playgroud)
行为:元素从底部到顶部(高度)增加
div与文本
<div style="height:20px;">20</div>
<div style="height:40px;">30</div>
<div style="height:60px;">40</div>
<div style="height:80px;">50</div>
Run Code Online (Sandbox Code Playgroud)
行为:元素从上到下(高度)增加
看到它在行动:http://jsfiddle.net/8GGYm/
下面的代码在chrome中工作正常但在firefox中没有.警报显示chrome中的适当边距,而在firefox中它始终显示0px.
HTML:
<div class="center">14</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.center {
margin: 0 auto;
width: 200px;
background-color: #ccc;
}
Run Code Online (Sandbox Code Playgroud)
JQuery:我正在使用最新的jQuery库
$(function(){
var center = $('.center').css('margin-left');
alert(center);
});
Run Code Online (Sandbox Code Playgroud)
请参阅firefox和chrome中的jsfiddle:http: //jsfiddle.net/vtbuz/2/