div默认是块状元素,新增一个div就要新开一行显示,启动display:inline后,将div的块状属性改为行内属性,所以两个div就可以在一行内显示了。
与其用div display:inline; 还不如直接用span,如果是布局div, 那最好还是用浮动(记得要清除浮动哦)或定位,各有优缺点
举例说明:
<head>
//清除浮动
<style type="text/css">
.clear{clear:both;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body><div style="border-left-color:black;
border-left-style: solid; //增加边框
border-left-width: 1px;
border-right-color: black;
border-right-style: solid;
border-right-width: 1px;
border-top-color: black;
border-top-style: solid;
border-top-width: 1px;
border-bottom-color: black;
border-bottom-style: solid;
border-bottom-width: 1px;
">
<span style="white-space:pre"> </span><div style="float:left;">文字1</div>
<span style="white-space:pre"> </span><div style="float:left;">文字2</div>
<span style="white-space:pre"> </span><div style="float:left;">文字3</div>
<span style="white-space:pre"> </span><div class="clear"></div> <span style="font-family: Arial, Helvetica, sans-serif;">//清除浮动,必须加</span>
</div>
</body>
</html>