在开发网页时,CSS经常用来设置文字的样式。其中,有一种很有趣的样式——一行文字在不同位置使用不同的颜色。这种样式很好看,也很有吸引力。 在CSS中,我们可以使用伪元素(::before 和 ::af
HTML <p class="colorful-text">这是一段文字,其中的某些字会在不同的颜色显示。</p> <br>
CSS .colorful-text { position: relative; } <br> .colorful-text::before { content: ""; position: absolute; z-index: -1; top: 0; left: 0; height: 100%; width: 50%; background-color: red; } <br> .colorful-text::after { content: ""; position: absolute; z-index: -1; top: 0; right: 0; height: 100%; width: 50%; background-color: blue; }
粉丝
0
关注
0
收藏
0