样式和颜色的多重文本装饰

时间:2022-05-01 20:22:37

I want to make a text with red wavy underline and blue dashed overline using text-decoration.
This is my code: (working only in Mozilla Firefox) (don't works, because display only overline)

我想用文字装饰用红色波浪下划线和蓝色虚线做一个文字。这是我的代码:(仅在Mozilla Firefox中工作)(不工作,因为只显示线)

span {
  font-size: 40px;
  text-decoration: underline wavy red;
  text-decoration: overline dashed blue;
}
<span> Some Text </span>

How can I do that effect using only text-decoration? (I know, it will work only in Mozilla Firefox)
Thanks for help.

3 个解决方案

#1


3  

You can not have two values for one css property at the same time.

您不能同时为一个css属性设置两个值。

Workaround: wrap yout text in another span and add separate text-decoration to each span:

解决方法:在另一个span中包装您的文本,并在每个span中添加单独的文本修饰:

span {
  font-size: 40px;
}

.wavy {
  text-decoration: underline wavy red;
}

.dashed {
  text-decoration: overline dashed blue;
}
<span class="wavy">
  <span class="dashed">Some Text </span>
</span>

#2


3  

Try This:

试试这个:

span {
    position: relative;
    text-decoration: underline wavy red;
    border-top: 2px dashed blue;
}
<span> Some Text </span>

Aswer your comment is here:

您的评论如下:

span {
    position: relative;
    text-decoration: underline wavy red;
}

span:after {
    position: absolute;
    width: 100%;
    height: 100%;
    display: block;
    content: '';
    border-top: 2px solid blue;
    top: 10px;
}
<span> Some Text </span>

#3


1  

A text will need to span over multiple lines, even a heading will do with narrow viewports found on smartphones.
Here's a multiline solution done with a linear gradient (well, 2 of them to reproduce the dashes):

文本需要跨越多行,即使是标题也需要使用智能手机上的窄视点。这是一个用线性梯度做的多线解(好吧,用其中的两个来再现破折号):

Codepen in Scss (simply using 2 variables for font-size and line-height)

Scss中的代码页(仅对字体大小和行高使用两个变量)

span {
  font-size: 40px;
  line-height: 1.5;
  text-decoration: underline wavy red;
  /*text-decoration: overline dashed blue;*/
  background-image:
    linear-gradient(to right, white 0, white 50%, transparent 50%, transparent 100%),
    linear-gradient(to bottom, blue 0, blue 1px, transparent 1px, transparent 100%);
  background-size:
    8px 100%,
    100% 60px;
  background-position: left top, left top;
  background-repeat: repeat, repeat;
}
<p><span> Some Text </span></p>

<p><span>Also<br>multiline</span></p>

Dashes can be freely modified (it's a gradient between transparent and white color, size them however you want)

破折号可以*修改(它是透明色和白色之间的渐变,可以随意修改大小)

#1


3  

You can not have two values for one css property at the same time.

您不能同时为一个css属性设置两个值。

Workaround: wrap yout text in another span and add separate text-decoration to each span:

解决方法:在另一个span中包装您的文本,并在每个span中添加单独的文本修饰:

span {
  font-size: 40px;
}

.wavy {
  text-decoration: underline wavy red;
}

.dashed {
  text-decoration: overline dashed blue;
}
<span class="wavy">
  <span class="dashed">Some Text </span>
</span>

#2


3  

Try This:

试试这个:

span {
    position: relative;
    text-decoration: underline wavy red;
    border-top: 2px dashed blue;
}
<span> Some Text </span>

Aswer your comment is here:

您的评论如下:

span {
    position: relative;
    text-decoration: underline wavy red;
}

span:after {
    position: absolute;
    width: 100%;
    height: 100%;
    display: block;
    content: '';
    border-top: 2px solid blue;
    top: 10px;
}
<span> Some Text </span>

#3


1  

A text will need to span over multiple lines, even a heading will do with narrow viewports found on smartphones.
Here's a multiline solution done with a linear gradient (well, 2 of them to reproduce the dashes):

文本需要跨越多行,即使是标题也需要使用智能手机上的窄视点。这是一个用线性梯度做的多线解(好吧,用其中的两个来再现破折号):

Codepen in Scss (simply using 2 variables for font-size and line-height)

Scss中的代码页(仅对字体大小和行高使用两个变量)

span {
  font-size: 40px;
  line-height: 1.5;
  text-decoration: underline wavy red;
  /*text-decoration: overline dashed blue;*/
  background-image:
    linear-gradient(to right, white 0, white 50%, transparent 50%, transparent 100%),
    linear-gradient(to bottom, blue 0, blue 1px, transparent 1px, transparent 100%);
  background-size:
    8px 100%,
    100% 60px;
  background-position: left top, left top;
  background-repeat: repeat, repeat;
}
<p><span> Some Text </span></p>

<p><span>Also<br>multiline</span></p>

Dashes can be freely modified (it's a gradient between transparent and white color, size them however you want)

破折号可以*修改(它是透明色和白色之间的渐变,可以随意修改大小)