【问题标题】:is this responsive css composition possible only with css?这种响应式 css 组合是否只能使用 css?
【发布时间】:2018-07-12 17:25:39
【问题描述】:

我有这个布局。

如果需要,我已包含 bootstrap 3。我无法让这个蓝色背景 div(包含文本)在图像下方拉伸全宽。

我得到的最接近的是制作 2 个(bs 网格)列,然后首先在列容器上使用 flexbox 使它们拉伸到相同的高度,然后在左列上弯曲以使内容垂直居中。但是这个蓝色背景只在左侧,没有拉伸整个宽度。

这可以仅使用 css 来制作吗?如果我制作一列并让蓝色 bg div 拉伸全宽,我必须绝对将图像放在右侧 - 但是我没有图像的高度。

编辑:这是我目前拥有的小提琴:

这是上一节

<div class="row flexrow">

  <!-- left column -->
  <div class="col-sm-6 flexcolumn">

    <div class="row bluebg">

      <h2>HEADING</h2>
      <p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum</p>

    </div>

  </div>

  <!-- right column -->
  <div class="col-sm-6">
    <img src="https://s10.postimg.org/q9ak7h9ah/image.png" class="wow fadeIn img-responsive" data-wow-duration="0.7s"

data-wow-delay="0.3s">

</div>
<!-- row -->

这是下一节

my fiddle - current layout

【问题讨论】:

  • 你试过什么?我假设您使用过引导网格系统,它使用浮点数。对于这种布局,您需要在imgheading 上使用position:absolute
  • 如果我在 img 上定位:绝对,我会放宽图像高度以使其具有响应性(与右列宽度成比例)
  • 我们无法调试图像,因此为了获得正确答案,请发布一个重现您描述的问题的工作代码 sn-p,否则您只会得到与给定答案类似的猜测。跨度>
  • @Yuray img 高度可以小于heading 高度,还是总是更大?
  • 总是更大(高度大于蓝色背景div)

标签: css layout twitter-bootstrap-3 responsive-design flexbox


【解决方案1】:

如果您希望它与另一个重叠,您的图像应该是position:absolute。 在评论 &lt;!-- left column --&gt; 下将您的 col-sm-6 更改为 col-sm-12

我在下面修改了你的代码

section#prev,
section#next {
  background: green;
  margin: 0;
  padding: 0;
}

.bluebg {
  background-color: rgba(50, 50, 200, .5);
}

section#mainsection {
  background-color: #cccccc;
  margin: 0;
  padding: 0;
}

.flexrow {
  display: flex;
  align-items: stretch;
  justify-content: center;
  position: relative;/*add this*/
  top: 0;/*add this*/
  left: 0;/*add this*/
  height: 299px;/*add this*/
}

.flexcolumn {
  display: block; /*update this*/
  align-items: center;
  justify-content: center;
  width: 100%; /*add this*/
  margin-top: 90px; /*add this*/
}
/*add below code*/
.newclass {
    position: absolute;
    top: 0;
    right: 50px;
}

.bluebg p {
    width: 55%;
}
<section id="prev">
  <h1>
  this is previous section
  </h1>
</section>


<section id="mainsection">


  <div class="container-fluid">


    <div class="row flexrow">

      <!-- left column -->
      <div class="col-sm-12 flexcolumn">

       <div class="row bluebg">

          <h2>HEADING</h2>
          <p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum</p>

       </div>
        <!-- right column -->
      <div class="newclass">
        <img src="https://s10.postimg.org/q9ak7h9ah/image.png" class="wow fadeIn img-responsive" data-wow-duration="0.7s" data-wow-delay="0.3s">
      </div>

      </div>

     

    </div>
    <!-- row -->

  </div>
  <!-- container -->

</section>


<section id="next">
  <h1>
  this is next section
  </h1>
</section>

希望这会有所帮助:)

【讨论】:

  • 它承诺 :),但如果你去整页,你会看到蓝色 bg 没有全宽拉伸......
  • 答案已更新。请检查我对 .flexcolumn 进行了一些更改
  • 谢谢,虽然这不是我想要的(因为我必须硬编码边距和 img 高度)我会使用你的解决方案并添加更多断点来实现我需要的。
  • 您可以使用 % 而不是像素的值来避免过多的断点。
猜你喜欢
  • 2014-06-29
  • 2022-08-24
  • 2012-01-07
  • 2011-06-08
  • 2019-06-16
  • 1970-01-01
  • 1970-01-01
  • 2017-04-03
  • 1970-01-01
相关资源
最近更新 更多