CSS - Multiple text-decorations with style and color

前端 未结 4 1877
悲哀的现实
悲哀的现实 2021-01-19 18:14

I want to make a text with red wavy underline and blue dashed overline using text-decoration.
This is my code: (working only in Mo

4条回答
  •  深忆病人
    2021-01-19 18:37

    You can specify multiple lines using text-decoration-line. You would think that you could specify a different colour and a different style for each line, however, this does not work, as you can see for yourself here:

    span {
      /* This does not work! */
      text-decoration-line: underline overline;
      text-decoration-style: wavy dashed;
      text-decoration-color: red blue;
    }
    Some Text

    This is what MDN says:

    CSS does not provide a direct mechanism for specifying a unique color for each line type. This effect can nevertheless be achieved by nesting elements, applying a different line type to each element (with the text-decoration-line property), and specifying the line color (with text-decoration-color) on a per‐element basis.

    So here is the solution using nesting:

    .parent {
      text-decoration: underline wavy red;
    }
    .child {
      text-decoration: overline dashed blue;
    }
    Some Text

提交回复
热议问题