在css中能否使一个字符以两种颜色呈现?
我的意思是例如字母"B",上半部分为红色,下半部分为蓝色。
h1 {
font-size: 72px;
background: -webkit-linear-gradient(red 49%, blue 50%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
请填写您自己的供应商前缀。
-webkit-background-clip: text; -webkit-text-fill-color: transparent;
- slynagh一个解决方案是:
<span class="half" title="B">B</span>
请注意,您需要设置属性值。
CSS:
.half {
font-size: 90px;
font-weight: bold;
position: relative;
color: blue;
line-height: 1em;
}
.half:before {
position:absolute;
content:''attr(title)'';
color: red;
height: .5em;
overflow: hidden;
}