响应式布局之min-width,max-width

本文介绍了CSS3中min-width和max-width属性在响应式布局中的作用。通过设置元素的最小和最大宽度,可以确保内容在不同屏幕尺寸下适配和展示。当容器宽度无法容纳所有浮动元素时,它们会自动换行,实现布局的自适应调整。

min-width表面这个div的最小宽度,而max-width限制这个div的最大宽度。因为我们将三个div都设置浮动,并且设置其最大的宽度,另外所以当容器的宽度不能够满足div宽度的时候,就会换行到下一行,从而实现响应式布局

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>响应式布局</title>
    <style type="text/css">
        article{
            width: 100%;
        }
        h1{
            text-align: center;
        }
        img {
            width: 100%;
            height: auto;
        }
        .one {
            min-width: 500px;
            border:1px solid red;
        }
        .two {
            background-color: #666;
        }
        .three {
            background-color: #ccc;
        }
        .float {
            max-width: 350px;
            float: left;
            text-align: justify;
            overflow-y: scroll;
        }
    </style>
</head>
<body>
    <article>
        <h1>Responsive Layout</h1>
        <div class="one float">
            <img src="1.jpg" alt="" >
        </div>
        <div class="two float">
            twotwotwotwotwotwotwotwotwotwotwotwotwotwotwotwotwotwotwo
            twotwotwotwotwotwotwotwotwotwotwotwotwotwotwotwotwovvvvv
        </div>
        <div class="three float">   1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
        </div>
    </article>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值