如何使用 CSS 在文本上应用阴影效果?

王林
王林 转载
2023-08-23 23:17:09 609浏览

如何使用 CSS 在文本上应用阴影效果?

我们可以使用CSS提供的“text-shadow”属性在文本元素上应用阴影效果。 “text-shadow”属性接受一个值列表,表示阴影相对于元素的X和Y偏移量,阴影的模糊半径以及阴影的颜色。 这些值在下面的语法中列出 -

语法

text-shadow: offset_y offset_x blur-radius color

以下是值及其含义的列表 -

  • Offset-x − 它表示阴影在水平方向上与元素的距离

  • Offset-y − It represents the distance of the shadow from the element in the vertical direction

  • 模糊半径 − 它表示阴影的不透明度

  • Color − It represents the color of the shadow

Example 1

在这个例子中,我们将在一个“h3”元素上应用阴影效果,并给阴影一个y偏移以及红色

<!DOCTYPE html>
<html lang="en">
<head>
   <title>How to Apply Shadow Effect on Text Using CSS?</title>
   <style>
   h3 {
      text-shadow: 0 15px 0 red;
   }
   </style>
</head>
<body>
   <h3>How to Apply Shadow Effect on Text Using CSS?</h3>
</body>
</html>

Example 2

在这个例子中,我们将在一个“h3”元素上应用阴影效果,并给阴影一个y偏移、x偏移、透明度和绿色。

<!DOCTYPE html>
<html lang="en">
<head>
   <title>How to Apply Shadow Effect on Text Using CSS?</title>
   <style>
      h3 {
         text-shadow: 10px 15px 5px green;
      }
   </style>
</head>
<body>
   <h3>How to Apply Shadow Effect on Text Using CSS?</h3>
</body>
</html>

结论

在本文中,我们学习了“text-shadow”属性,并使用CSS将阴影效果应用于文本元素,通过2个不同的示例进行了演示。在第一个示例中,我们应用了一个垂直阴影效果,颜色为“红色”,而在第二个示例中,我们应用了一个垂直和一个水平阴影效果,颜色为“绿色”,模糊半径为5px。

以上就是如何使用 CSS 在文本上应用阴影效果?的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除