float布局时,所有li是一行,内容不固定时,高度不等。
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
div {
border: 1px solid green;
padding: 10px;
margin: 10px;
}
ul {
overflow: hidden;
}
ul li {
float: left;
width: 100px;
border: 1px solid red;
word-break: break-all;
text-align: center;
list-style: none;
vertical-align: middle;
}
</style>
</head>
<body>
<div>
<ul>
<li>111111111111111111111111111111111111111111111111111111</li>
<li>2222</li>
<li>3333</li>
<li>4444</li>
</ul>
</div>
</body>
</html>
table布局时,所有li是一行,内容不一样时,高度一样。
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
div{
display: table;
border: 1px solid green;
padding: 10px;
margin: 10px;
}
ul{
display: table-row;
}
ul li{
display: table-cell;
width: 100px;
border: 1px solid red;
word-break:break-all;
text-align: center;
list-style: none;
vertical-align: middle;
}
</style>
</head>
<body>
<div>
<ul>
<li>111111111111111111111111111111111111111111111111111111</li>
<li>2222</li>
<li>3333</li>
<li>4444</li>
</ul>
</div>
</body>
</html>