(bootstrap学习)flex布局

效果图

中屏及以上显示效果在这里插入图片描述


中屏以下显示

在这里插入图片描述


代码部分

    <style>
        .p-2{
            background-color: lightblue;
            border: 1px solid black;
        }
        .f-item{
            width: 200px;
            height: 200px;
            background-color: lightblue;
        }
        .d-flex > .f-item:nth-of-type(2){
          flex:0 1 1720px;
          background-color: white;
      }
    
      @media screen and (max-width: 768px)  {
                .item1{
                    display: none;
                }
                .item3{
                    display: none;
                }
            }


    </style>
</head>
<body>
    <div class="header" style="background-color:rgb(0, 0, 145); min-height: 100px; ">header</div>
    <div class="d-flex flex-row">
        <div class="f-item item1">item1</div>
        <div class="f-item item2">item2</div>
        <div class="f-item item3">item3</div>
    </div>
    <div class="footer" style="background-color:rgb(0, 0, 145); min-height: 50px; ">footer</div>
</body>
Bootstrap是一个流行的前端开发框架,它提供了一套用于快速构建响应式网页的工具和组件。其中的Flex布局系统是用于实现灵活的水平布局的一部分。 Flex布局是一种基于弹性盒子模型的布局方式,通过使用flex容器和flex项目来实现灵活的布局。在Bootstrap中,可以使用flex类来应用Flex布局。 要实现水平布局,可以使用以下步骤: 1. 创建一个flex容器:使用`d-flex`类来创建一个flex容器。这个类可以应用在任何父元素上,例如一个div元素。 2. 添加flex项目:在flex容器中添加需要布局的元素作为flex项目。使用`flex-fill`类来使项目填充剩余空间,并且使用`flex-grow-0`类来禁止项目自动扩展。 3. 设置水平对齐方式:使用`justify-content-*`类来设置项目在水平方向上的对齐方式。常用的对齐方式包括`justify-content-start`(左对齐)、`justify-content-center`(居中对齐)和`justify-content-end`(右对齐)。 4. 设置项目间距:使用`gap-*`类来设置项目之间的间距。常用的间距值包括`gap-1`、`gap-2`等。 下面是一个示例代码,展示了如何使用BootstrapFlex布局实现水平布局: ```html <div class="d-flex justify-content-between gap-2"> <div class="flex-fill">项目1</div> <div class="flex-fill">项目2</div> <div class="flex-fill">项目3</div> </div> ``` 这个示例代码创建了一个flex容器,并在容器中添加了三个flex项目。这三个项目会自动填充剩余空间,并且通过`justify-content-between`类将它们在水平方向上均匀分布。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值