第一列由内容的宽度撑开,并不设置宽度,第二列自适应 第一种方案
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
body,p{
margin: 0;
padding: 0;
}
.left{
background: yellowgreen;
float: left;
margin-right: 20px;
}
.right{
overflow: hidden;
background: pink;
}
/*设置.left元素下面的内容*/
.left p{
width: 300px;
}
</style>
</head>
<body>
<div class="parent">
<div class="left">
<p>left</p>
</div>
<div class="right">
<p>right</p>
<p>right</p>
</div>
</div>
</body>
</html>
第二种方案table
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
body,p{
margin: 0;
padding: 0;
}
.parent{
display: table;
width: 100%;
}
.left{
padding-right: 20px;
width: 0.1%;
display: table-cell;
}
.right{
background: pink;
display: table-cell;
}
.left p{
width: 300px;
background: yellowgreen;
}
</style>
</head>
<body>
<div class="parent">
<div class="left">
<p>left</p>
</div>
<div class="right">
<p>right</p>
<p>right</p>
</div>
</div>
</body>
</html>
第三种方案
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
body,p{
margin: 0;
padding: 0;
}
.parent{
display: flex;
}
.left{
padding-right: 20px;
}
.right{
background: pink;
flex: 1;
}
.left p{
width: 300px;
background: yellowgreen;
}
</style>
</head>
<body>
<div class="parent">
<div class="left">
<p>left</p>
</div>
<div class="right">
<p>right</p>
<p>right</p>
</div>
</div>
</body>
</html>
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有