首页 > 解决方案 > 全角响应式两列布局图像和文本

问题描述

我正在寻找线索来设计像本页顶部这样的横幅:https ://www.gazteaukera.euskadi.eus/inicio/

我正在尝试自己,但没有得到我想要的(见下文)。我希望左侧的图像列和右侧的文本列完全对齐。我希望它具有响应性,以便在较小的屏幕中,左列将放置在右列的顶部(顶部和底部 div 之间没有空间)。

我在获得我想要的东西时遇到了一些问题。我希望有一个人可以帮助我 :)

代码:

    .row {
      background-color: blue;
      padding: 0px;
    /*I have added a background-color to help me solve the design issues, but this is sthg to be removed*/}
    
    .column {
      float: left;
      width: 50%;
      padding: 0px;
     }
     
    .row:after {
      content: "";
      display: table;
      clear: both;
    }
    
    .title {
    font-size: 24px;
    color: #0FD955;
    padding: 15px 15px 0px 15px;
    font-weight: bold;}
    
    .text {
    font-size: 18px;
    color: #0FD955;
    padding: 0px 15px 15px 15px;
    }
    
    .imgw100 {
    width: 100%;
    }
    
    @media screen and (max-width: 980px) {  
      .column {    width: 100%;  }
        .right {    width: 100%;  }
      .left {    width: 100%;  }
    
    }
    <div class="row">
      <div class="column right">
      <img class="imgw100" src="https://butterfly-conservation.org/sites/default/files/styles/masthead/public/2019-03/16548509661_3bdddd5179_o.jpg" />
      </div>
      <div class="column left" style="background-color: #022C11;">
        <p class="title">Breaking news</p>
        <p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </div>
    </div>

标签: htmlcssmedia-queries

解决方案


将显示 css 添加到行作为较大设备的 flex 添加用于小屏幕 添加显示 css 作为行块

.row {
    background-color: blue;
    padding: 0px;
    display: flex;
}

.title {
    font-size: 24px;
    color: #0fd955;
    padding: 15px 15px 0px 15px;
    font-weight: bold;
}

.text {
    font-size: 18px;
    color: #0fd955;
    padding: 0px 15px 15px 15px;
}

.imgw100 {
    width: 100%;
}

@media screen and (max-width: 480px) {
    .row {
        background-color: blue;
        padding: 0px;
        display: block;
    }
}


推荐阅读