使背景图像比容器宽,但仅在一侧

时间:2019-03-08 12:46:04

标签: css html5 css3 background-image full-width

我正在尝试使背景图像的宽度大于其父容器的宽度。这与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上的链接。

这是我想要实现的:

enter image description here

0 个答案:

没有答案