【问题标题】:Fullwidth responsive two column layout image and text全角响应式两列布局图像和文本
【发布时间】:2021-02-07 02:39:11
【问题描述】:

我正在寻找线索来设计一个类似本页顶部的横幅: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>

【问题讨论】:

    标签: html css media-queries


    【解决方案1】:

    将显示 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;
        }
    }
    
    

    【讨论】:

    • 谢谢!我不熟悉引导程序。我会检查一下,但我希望有一些方法可以使用纯 HTML 和 CSS。
    • 我将编辑答案,请检查此
    • 嗨 Dinesh,非常感谢您的帮助,但它似乎不起作用。我将尝试使用引导程序。
    猜你喜欢
    • 1970-01-01
    • 2016-04-22
    • 2015-12-30
    • 2013-07-27
    • 2014-02-11
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多