【问题标题】:Linear Gradient Background with white text带白色文本的线性渐变背景
【发布时间】:2019-02-25 21:36:03
【问题描述】:

所以我的导航栏中有标题。文字有线性渐变

nav li h1 {
background-image:linear-gradient(90deg,red,#ffae00);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent; }

我想让标题变成白色,背景保持线性渐变

例子:

https://jsfiddle.net/qx96ku4h/

【问题讨论】:

  • html中的a在哪里?
  • 别介意,它不是一个链接。这几乎是一个 JSS 按钮,可以向上滚动到页面顶部

标签: html css


【解决方案1】:

只需将值放回initial 即可禁用文本渐变并设置文本颜色。

header {
  position: fixed;
  background: #23262b;
  right: 0;
  left: 0;
  top: 0;
  height: 100px;
  z-index: 9999;
}

header:after {
  content: "";
  background: -webkit-linear-gradient(30deg, red, #ffae00);
  display: block;
  height: 5px;
  width: 100%;
  position: absolute;
  bottom: 0;
}

nav ul {
  list-style-type: none;
  padding: 0;
  margin: -9px;
  margin-left: 20px;
}

nav li {
  display: inline-block;
  position: relative;
  text-align: center;
  letter-spacing: 1px;
  font-weight: 900;
  margin: 20px;
}

nav li {
  color: white;
  text-decoration: none;
  text-transform: uppercase;
}


nav li h1 {
  background-image: linear-gradient(90deg, red, #ffae00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  color: #fff;
  padding: 20px;
  margin: 0;
}

#myBtn:hover h1 {
  -webkit-background-clip: initial;
  -webkit-text-fill-color: initial;
  border-radius: 20px;
}
<header>
  <nav>

    <ul>
      <li onclick="topFunction()" id="myBtn" title="Go to top">
        <h1>Make text White</h1>
      </li>

    </ul>
  </nav>
</header>

【讨论】:

  • Temani 你知道我怎样才能让标题的背景变得更大更厚吗?因为文本几乎不在背景中。
  • @AdrianB。我还为此添加了一些填充
  • 是的,抱歉,lol 错过了填充。再次感谢你:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-01
  • 2011-03-05
  • 1970-01-01
  • 2022-12-21
  • 2021-07-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多