HTML DOM Style textShadow 属性

htmlweb developmentfront end technology更新于 2025/6/9 5:32:17

HTML DOM Style textShadow 属性返回并应用当文本在 HTML 文档中超出元素容器范围时应发生的情况。

语法

以下是语法 −

  • 返回 textShadow

object.style.textShadow
  • 修改 textShadow

object.style.textShadow = “value”

值

此处,值可以为 -

值说明
inherit从其父元素继承此属性值。
initial将此属性值设置为其默认值。
none文本无阴影。
h-shadow v-shadow blur color文本有阴影。
其中
h-shadow 表示水平阴影的值。
v-shadow 表示垂直阴影的值。
blur 表示模糊距离。
color 表示阴影的颜色。

示例

让我们看一个 style textShadow 属性的示例 −

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      color: #000;
      background: lightblue;
      height: 100vh;
   }
   p {
      margin: 1.5rem auto;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
   }
</style>
</head>
<body>
<h1>DOM Style textShadow Property Example</h1>
<p>Some Dummy Text</p>
<button onclick="add()" class="btn">Set textShadow</button>
<script>
   function add() {
      document.querySelector('p').style.textShadow = "10px 10px 2px #db133a";
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击"设置文本阴影"按钮为段落文本应用阴影。


相关文章


有用资源