1

我正在尝试使背景图像比其父容器更宽。它与此codepen非常相似,但我想让背景图像仅在一侧(右侧)比容器更宽,以便图像为视口宽度的 50%。

<div class="container">
  <div class="flex-container">
    <div class="flex-box flex-text">
     <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>
    </div>
    <div class="flex-box bcg-image"></div>
  </div>
</div>

CSS 代码:

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.flex-container {
  display: flex;
}

.flex-box {
  flex: 1;
}

.flex-text {
  padding-right: 20px;
}

.bcg-image {
  background-repeat: no-repeat;
  background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/hero.jpg);
  background-attachment: scroll;
  background-position: center center;
  background-size: cover;
}

这是我的codepen上的链接。

这就是我想要实现的目标:

在此处输入图像描述

4

0 回答 0