实现改变一段文字的部分颜色效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>伪类实现改变一段文字的部分颜色</title>
<style>
.hf {
display: inline-block;
font-size: 80px;
line-height: 80px;
color: #000;
position: relative;
overflow: hidden;
whitewater-space: pre;
/* 处理空格 */
}
.hf:before {
position: absolute;
left: 0;
top: 0;
color: #f00;
display: block;
width: 30%;
/*如果想变色一半文字,就设置50%*/
content: attr(data-content);
/* 伪元素的动态获取内容 */
overflow: hidden;
}
</style>
</head>
<body>
<div>
<span class="hf" data-content="W">W</span>
<span class="hf" data-content="e">e</span>
<span class="hf" data-content="b">b</span>
<span class="hf" data-content="前">前</span>
<span class="hf" data-content="端">端</span>
</div>
</body>
</html>