简体   繁体   English

带有白色文本的线性渐变背景

[英]Linear Gradient Background with white text

So I have the Title in my Navbar. 所以我的导航栏中有标题。 The text has a linear gradient 文字具有线性渐变

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

and I want the title to turn white and the background stay linear gradient 我想标题变成白色,背景保持线性渐变

Example: 例:

https://jsfiddle.net/qx96ku4h/ https://jsfiddle.net/qx96ku4h/

Simply put the values back to initial to disable the gradient on text and set the color of the text. 只需将值恢复为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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM