将文字放在两种不同的纯色背景上

时间:2017-07-10 16:54:33

标签: html css background-color

有谁知道如何在两种不同的纯色背景上放置文字?同时,它在最小化屏幕时仍然保持响应。我已经看到这很多,但是,我仍在研究编码这种风格的标准方法。下面我添加了我想要做的风格的图像。感谢您的时间。

image displaying text over two solid colors

2 个答案:

答案 0 :(得分:0)

这可能会对你有所帮助。 https://jsfiddle.net/67uxvnq7/1/



.div1 {
  position: relative;
  width: 100%;
  height:50vh;
  background: pink;
}

.div2 {
  position: relative;
  width: 100%;
  height: 50vh;
  background: red;
}

span {
  font-size: 50px;
  font-weight:bold;
  color: #000;
  position: absolute;
  bottom: -25px;
  z-index:1;
  width:100%;
  text-align:center;
}

<div class="div1">
  <span>HELLO WORLD</span>
</div>
<div class="div2">

</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我仍然认为CSS渐变是要走的路。如果需要,您可以设置颜色停止位置。它也不依赖于设定高度。

&#13;
&#13;
div {
  background-image: linear-gradient(to bottom, #ee615f, #ee615f 50%, #9f3e3e 50%, #9f3e3e);
  font-family: sans-serif;
  font-size: 40px;
  line-height: 1;
  padding: 25px 0;
  margin-bottom: 25px;
  text-align: center;
}

#div2 {
  background-image: linear-gradient(to bottom, #ee615f, #ee615f 25%, #9f3e3e 25%, #9f3e3e);
}

#div3 {
  background-image: linear-gradient(to bottom, #ee615f, #ee615f 75%, #9f3e3e 75%, #9f3e3e);
}
&#13;
<div id="div">COLOR STOP AT 50%</div>

<div id="div2">COLOR STOP AT 25%</div>

<div id="div3">COLOR STOP AT 75%</div>
&#13;
&#13;
&#13;

以下是有关使用它们的更多信息:https://css-tricks.com/css3-gradients/

相关问题