【问题标题】:How to make full height image with vertical text on center and left align witth background overlay image如何使全高图像在中心和左对齐垂直文本与背景叠加图像
【发布时间】:2019-04-05 15:20:53
【问题描述】:

如何制作顶部有黑色覆盖的全高图像(从上到中到下)

0% -> 35% -> 0%

<header style="background: url(...image..);">
  <h2>title</h2>
  <p>description...</p>
</header>

【问题讨论】:

  • 到目前为止你尝试过什么?

标签: html css sass


【解决方案1】:

我只是写了一个基本的background-imageblack overlay 代码。试试这个,希望能帮到你。谢谢

header {
  background-repeat: no-repeat;
  background-size: cover;
  color: #fff;
  display: flex;
  align-items: center;
  height: 100vh;
  position: relative;
  width: 100%;
}

header:before {
  background-image: linear-gradient(to bottom, rgba(0,0,0,0), rgba(0,0,0,0.35), rgba(0,0,0,0));
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0.5;
  height: 100%;
  width: 100%;
}

.content {
  margin-left: 20px;
  position: relative;
}
<header style="background-image: url('https://images.unsplash.com/photo-1476820865390-c52aeebb9891?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80')">
  <div class="content">
    <h2>Title</h2>
    <p>Description...</p>
  </div>
</header>

【讨论】:

  • 唯一的问题是我需要 html 中的 url 而不是 css 中的 url,因为我需要附加 =$image['banner']?> 但这个脚本适用于其他
  • 我只是更新了上面的代码sn-p,只对CSS做了一些改动。我将 background-imagecss 移动到 html。谢谢
  • hmm 覆盖顶部在哪里:0% 中心 35% 底部 0% 不透明度?
  • 对不起,我只是忘记更新我的编辑。我刚刚添加了叠加层 top opacity: 0middle opacity: 0.35bottom opacity: 0。如果你想增加中间的覆盖,只需更改 0.35。谢谢
  • tnx 对我帮助很大!
猜你喜欢
  • 2012-11-06
  • 1970-01-01
  • 2012-02-24
  • 2015-02-20
  • 1970-01-01
  • 1970-01-01
  • 2013-05-19
  • 2021-08-24
  • 1970-01-01
相关资源
最近更新 更多