【问题标题】:Change Color of Text Within Paragraph Without Using Span?在不使用跨度的情况下更改段落内文本的颜色?
【发布时间】:2021-09-19 11:43:13
【问题描述】:

CSS 多年来已经取得了很大进步,我想知道是否有一种方法可以在不使用跨度的情况下更改段落中部分文本的颜色?例如,在 CSS 中是否有任何方法可以将段落的前 10 个字符变为红色?

【问题讨论】:

  • 不,这是不可能的 CSS 你需要 javascript

标签: html css text colors formatting


【解决方案1】:

经典的背景颜色,但你需要一个等宽字体

span {
  font-family:monospace;
  font-size:25px;
  color:#0000;
  background:
    /* 10 characters in red and the remaining in black */
    linear-gradient(90deg, red 0 10ch, #000 0);
  -webkit-background-clip:text;
  background-clip:text;
}
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque congue malesuada efficitur. Etiam ut rhoncus diam. Proin a maximus erat, quis ultrices nisl. Aenean tincidunt risus id massa tempor tempor. Mauris ac odio pulvinar elit porta tincidunt. Curabitur sit amet mauris vitae tortor </span>

【讨论】:

    猜你喜欢
    • 2013-02-02
    • 1970-01-01
    • 2012-06-21
    • 2013-07-05
    • 2019-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-30
    相关资源
    最近更新 更多