Take 2 columns in 2-columns layout but not when 1-column layout in CSS grid without @media

前端 未结 3 1682
面向向阳花
面向向阳花 2021-01-25 09:09

The desired layout for wide screens:

The desired layout for narrow screens:

Initial CSS:

.La         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-25 09:20

    A posible solution using flex, like MichaelT

    .layout {
      border: solid 1px black;
      margin: 2px;
      position: relative;
    }
    
    
    .innerlayout {
      display: flex;
      flex-wrap: wrap;
      position: relative;
      left: -10px;
      right: 10px;
      width: calc(100% + 20px);
    }
    
    span {
        background-color: green;
        height: 40px;
        min-width: 240px;
        width: 40%;
        margin: 15px 10px;
        flex-grow: 1;
    }
    
    .wide {
        width: 100%;
        background-color: red;
    }
    
    #narrow {
        width: 300px;
    }

提交回复
热议问题