正常情况下我们设置span标签是无法设置span标签的宽度和高度的。那么怎样才能设置呢。个人感觉意义并不大,如果需要可以使用div。
span是有display:inline-block和float属性的,只要设置了这两个属性,就会认为它是一个块级元素。
下面是例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>关于span标签的宽度和高度</title>
</head>
<body>
<span style="width:400px;height:50px;background-color:red">无浮动和inline-block</span>
<span style="width:400px;height:50px;background-color:red;float:left">有浮动和inline-block</span>
<span style="width:400px;height:50px;background-color:red;display:inline-block;">无浮动和有inline-block</span>
</body>
</html>
显示效果: