代码如下:
<html>
<head>
<title>test</title>
</head>
<body>
<div><span>shanghai</span><span class="margin"> </span><span>male</span></div>
</body>
</html>
.margin {
width:40px;
height:auto;
}
最佳答案
你不能给它一个宽度,因为它是一个内联元素。
This property specifies the content width of boxes generated by block-level and replaced elements. This property does not apply to non-replaced inline-level elements. -- CSS 2.1 Width property
您可以通过将其改为 block 或内联 block 元素来解决此问题:
display:inline-block
但是,某些浏览器可能不支持此功能。但是,您可能会获得相同的结果:
margin-left:40px
关于css - 为什么类(class)利润率不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1057353/