两列布局,左边定宽100px,右边自适应?

1)使用flex布局,父容器设置display:flex,左边div设置flex:0 0 100px width:100px height:100px;右边div设置:flex:1 height:100px

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            .container{
   
                background:red;
                display: flex;
                -webkit-display:flex;
            }
 
            .d1{
   
                background:rgba(2,55,66,0.5);
                flex: 0 0 100px;
                width:100px;
                height:100px;
          
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用 CSS Grid 布局来实现左边独占一行一列,右边一列分为上下两行,高度等于左边高度的布局。以下是一个实现示例: HTML代码: ```html <div class="container"> <div class="item item1">左边独占一行一列</div> <div class="item item2">右边一列</div> <div class="item item3">上</div> <div class="item item4">下</div> </div> ``` CSS代码: ```css .container { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: minmax(100px, auto); grid-gap: 10px; } .item { background-color: #ddd; padding: 20px; text-align: center; } .item1 { grid-row: 1 / 2; grid-column: 1 / 2; } .item2 { grid-row: 1 / 3; grid-column: 2 / 3; display: grid; grid-template-rows: 1fr 1fr; grid-gap: 10px; } .item3 { background-color: #eee; } .item4 { background-color: #ccc; } ``` 在上面的代码中,`.container` 是一个 CSS Grid 容器,我们通过设置 `grid-template-columns` 和 `grid-auto-rows` 属性来义容器的列和行数,这里我们义了 2 列和自动行数,并且使用 `minmax()` 函数来设置行的最小和最大值,以便实现高度等于左边高度的效果。 接着,我们通过设置子元素的 `grid-row` 和 `grid-column` 属性来控制子元素在网格中的位置和大小,来实现左边独占一行一列和右边一列分为上下两行的布局。同时,我们通过为 `.item2` 设置 `display: grid` 和 `grid-template-rows` 属性来实现右边一列分为上下两行的效果。 需要注意的是,我们在 `.item2` 的子元素中,没有设置具体的行数,而是使用了自动行数。这是因为我们希望子元素的高度自适应,以便实现高度等于左边高度的效果。 通过这种方式,我们就可以使用 CSS Grid 布局来实现左边独占一行一列,右边一列分为上下两行,高度等于左边高度的布局

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值