扫码关注官方订阅号
如图,左边的头像部分是固定的,但是右边的宽度是随着父元素的宽度而变化的,虽然可以通过js计算后来控制它的宽,我想问可不可以用纯css来实现?
欢迎选择我的课程,让我们一起见证您的进步~~
<p class="a1" style="position: relative;"> <p class="a2" style=" width: 100px; height: 100px; position: absolute; left: 0; top: 0; background: red;"></p> <p class="a3" style=" margin-left: 120px; background: blue; height: 100px;"></p> </p>
Demo:https://jsfiddle.net/23d8e966/
<p class="comment"> <p class="avatar"></p> <p class="comment-content"></p> </p>
.comment { position: relative; } .comment .avatar { left: 10px; top: 0; width: 40px; height: 40px; position: absolute; background: #999; } .comment-content { height: 100px; border: 1px solid #eee; background: #fff; margin-left: 60px; }
<p> <p class="left"></p> <p class="right"></p> </p> <style> .left{ float: left; width: 200px; height: 50px; background-color: rgba(0,0,255,0.5); } .right{ margin-left: 210px; height: 50px; background-color: rgba(255, 0, 0, 0.5); } </style>
两列自适应布局比较简单,让定宽一列脱离文档流就好了,使用absolute、float都可以。相关拓展关键词:双飞翼布局、圣杯布局
absolute
float
可以用css3的flex
.left {float:left; width:100px; height: 300px; background:#333} .main{ overflow: hidden; height: 300px; background:#f22} <p class="left"></p> <p class="main"></p>
关键字:BFC
BFC
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
Demo:https://jsfiddle.net/23d8e966/
两列自适应布局比较简单,让定宽一列脱离文档流就好了,使用
absolute、float都可以。相关拓展关键词:双飞翼布局、圣杯布局
可以用css3的flex
关键字:
BFC