CSS实现响应式布局(自动拆分几列)
1.css代码
<style type="text/css"> .container{ margin-top: 10px; } .outerDiv{ float:left; width:100%; } /* 大于648像素一行两个div,innerDiv两个宽度为:(300+4+20)*2 */ @media screen and (min-width: 648px){ .outerDiv { width: 50% } } .innerDiv{ min-width: 300px; height: 80px; border-radius: 10px; border: 2px solid #4a403f; margin: 2px 10px; background-color: #99ccff; color:#beb2b2; font-family: Arial; font-size:18px; } </style>
2.网页代码
<div class="container"> <div class="outerDiv"> <div class="innerDiv"> </div> </div> <div class="outerDiv"> <div class="innerDiv"> </div> </div> <div class="outerDiv"> <div class="innerDiv"> </div> </div> <div class="outerDiv"> <div class="innerDiv"> </div> </div> <!-- 清除浮动 --> <div style="clear: both"></div> </div>
3.总结
容器里的outerDiv作为布局模块,宽度由窗口大小决定拆分比例,采用流动布局。innerDiv作为布局模块里面的真正内容,宽度不要指定100%,否则加上边框无法计算了。模块之间的间隔,需在innerDiv里面设置margin。
相关推荐
xiaohuli 2020-07-28
hellowzm 2020-08-18
AlisaClass 2020-07-19
qiupu 2020-11-04
多读书读好书 2020-11-03
RedCode 2020-10-28
jiedinghui 2020-10-25
Ladyseven 2020-10-22
hellowzm 2020-10-12
zuncle 2020-09-28
Ladyseven 2020-09-11
jiedinghui 2020-09-07
xiaohuli 2020-09-02
葉無聞 2020-09-01
impress 2020-08-26
ThikHome 2020-08-24
nicepainkiller 2020-08-20