css中div超出自动换行

 

目录

页面样式

html页面代码

scss样式代码


页面样式

 这是布局完成之后的整个页面的布局,可以看到每行显示两个div

html页面代码

 <div className='home'>
        <div className='top'>
            <h1>购物商城</h1>
        </div>
        <div className='center'>
            <div>1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
            <div>4</div>
            <div>4</div>
            <div>4</div>
            <div>4</div>
        </div>
    </div>

在center大盒子中有8个div盒子,我们需要让他均匀的分布在页面

scss样式代码

.home{
    width: 100vw;
    height: 100vh;
    background-color: lightblue;
    .top{
        width: 100vw;
        height:60px;
        background-color: lightgray;
        h1{
            text-align: center;
            line-height: 60px;
        }
    }
    .center{
        width: 100vw;
        height: calc(100vh - 60px);
        background-color: lightcoral;
        display: flex; //把盒子在一行显示
        overflow-x: hidden; //超出隐藏
        flex-wrap: wrap;  //超出自动换行
        div{
            width: 48%;
            height: 200px;
            background-color: lightseagreen;
           margin: 10px 5px 10px 5px;
        }
    }
}

我们先是通过display:flex把所有的div整到一行中,overflow:hidden超出部分隐藏,flex-wrap:wrap超出自动换行

margin属性四个值的先后顺序是:margin-top,margin-right,margin-buttom,margin-left

  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值