1 回答
TA贡献1827条经验 获得超7个赞
要让父元素的宽度是所有子元素的宽度之和,那就是说跟据内容自适应,设置父元素的display: inline-block;;
要让子元素不换行,在父元素上设置white-space: nowrap
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div {
white-space: nowrap;
display: inline-block;
border: 1px solid #f00;
}
p {
width: 100px;
height: 100px;
display: inline-block;
border: 1px solid #00f;
}
</style>
</head>
<body>
<div>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
</div>
</body>
</html>
添加回答
举报