使用 HTML & CSS 创建霓虹灯文本显示


如今,在网页上创建霓虹灯文本是一种使其更具吸引力的趋势。我们可以创建网页上的霓虹灯文本,以产生醒目的效果,并吸引用户注意网页包含的重要信息。

我们可以将霓虹灯文本与徽标、标题、广告等一起使用,以突出显示它们。在本教程中,我们将自定义 text-shadow CSS 属性的值以创建霓虹灯文本。

语法

用户可以遵循以下语法使用 HTML 和 CSS 创建霓虹灯文本。

text-shadow: 0 0 1.5rem white;

我们在上述语法中使用了“text-shadow” CSS 属性来添加发光效果。它将水平偏移量作为第一个值,垂直偏移量作为第二个值,模糊半径作为第三个值,颜色作为第四个值。

我们始终需要为垂直和水平偏移量设置为 0。为了生成霓虹灯效果,我们需要为 text-shadow CSS 属性使用多个具有不同颜色和模糊半径的值。

示例 1(基本霓虹灯文本)

在下面的示例中,我们使用“text-shadow” CSS 属性为文本创建了基本霓虹灯效果。我们使用多个具有不同 border-radius 和颜色的值来生成霓虹灯效果。

在输出中,用户可以看到带有霓虹灯效果的文本。

<html>
<head>
   <style>
      .neon {
         font-size: 5rem;
         color: white;
         font-family: 'Arial', sans-serif;
         text-shadow: 0 0 1.5rem white, 0 0 3.5rem white, 0 0 5rem white, 0 0 7rem #ff00de, 0 0 8rem #ff00de, 0 0 10rem #ff00de, 0 0 12rem #ff00de, 0 0 15rem #ff00de;
      }
   </style>
</head>
<body>
   <h2> Creating the <i> basic Neon text </i> using the CSS. </h2>
   <div class = "neon"> Neon Text </div>
   </html><html>
   <head>
      <style>
         .neon {
            font-size: 5rem;
            color: white;
            font-family: 'Arial', sans-serif;
            text-shadow: 0 0 1.5rem white, 0 0 3.5rem white, 0 0 5rem white, 0 0 7rem #ff00de, 0 0 8rem #ff00de, 0 0 10rem #ff00de, 0 0 12rem #ff00de, 0 0 15rem #ff00de;
         }
      </style>
   </head>
<body>
<h2> Creating the <i> basic Neon text </i> using the CSS. </h2>
<div class = "neon"> Neon Text </div>
</html>

示例 2(彩虹霓虹灯文本)

在下面的示例中,我们在文本中创建了彩虹霓虹灯效果。在这里,我们在 div 元素中添加了文本。

我们在 CSS 中使用了“background-image” CSS 属性来添加线性渐变作为背景。我们在 45 度角应用了 4 种不同颜色的线性渐变。此外,我们使用了“-webkit-background-clip” CSS 属性以文本的形状裁剪背景图像。

此外,我们使用了“-webkit-text-fill-color” CSS 属性将透明颜色填充到文本中。因此,它将填充与背景相同的颜色。此外,我们使用了带有“rainbow-keyframe” 关键帧的动画 CSS 属性。在关键帧中,我们更改“hue-rotate”的度数以旋转背景中的色调。

在输出中,用户可以看到文本中的彩虹效果。

<html>
<head>
   <style>
      .rainbow-neon {
         font-size: 5rem;
         background-image: linear-gradient(45deg, #f3626b, #6181ff, #a25bf2, #ffc100);
         -webkit-background-clip: text;
         -webkit-text-fill-color: transparent;
         animation: rainbow-keyframe 3s linear infinite;
      }
      @keyframes rainbow-keyframe {
         0% {
            filter: hue-rotate(0deg);
         }
         100% {
            filter: hue-rotate(360deg);
         }
      }
   </style>
</head>
<body>
   <h2> Creating the <i> rainbow Neon text </i> using the CSS </h2>
   <div class="rainbow-neon"> It's raining actually. </div>
</body>
</html>

示例 3(闪烁的霓虹灯文本)

在下面的示例中,我们创建了闪烁的霓虹灯文本。在这里,我们使用“text-shadow” CSS 属性为文本添加霓虹灯效果。此外,我们使用“animation”属性添加闪烁动画。在“flickering”关键帧中,我们更改“text-shadow”属性的值。

在输出中,我们可以看到带有发光效果的闪烁文本。

<html>
<head>
   <style>
      .flicker {
         font-size: 4rem;
         color: blue;
         text-shadow: 0 0 1.5rem white, 0 0 3.5rem white, 0 0 5rem white, 0 0 7rem #ff00de, 0 0 8rem #ff00de, 0 0 10rem #ff00de, 0 0 12rem #ff00de, 0 0 15rem #ff00de;
         color: #fff;
         animation: flicker 0.5s linear infinite;
      }
      @keyframes flicker {
         0%, 5%, 10%, 15%, 20%, 25%, 30%, 35%, 40%, 45%, 50%, 55%, 60%, 65%, 70%, 75%, 80%, 85%, 90%, 95%, 100%
         { text-shadow: 0 0 1.5rem white, 0 0 3.5rem white, 0 0 5rem white, 0 0 7rem #ff00de, 0 0 8rem #ff00de, 0 0 10rem #ff00de, 0 0 12rem #ff00de, 0 0 15rem #ff00de;
         }
         1%, 6%, 11%, 16%, 21%, 26%, 31%, 36%, 41%, 46%, 51%, 56%, 61%, 66%, 71%, 76%, 81%, 86%, 91%, 96%
         {
            text-shadow: none;
         }
      }
   </style>
</head>
<body>
   <h2> Creating the <i> flickering Neon text </i> using the CSS. </h2>
   <div class = "flicker"> This text is flickering. </div>
</body>
</html>

示例 4(渐变霓虹灯文本)

在下面的示例中,我们在文本中添加了渐变。我们使用“background-image”属性将渐变应用于文本。

在输出中,用户可以看到带有渐变的文本颜色。此外,用户可以通过将不同的颜色值传递给 linear-gradient() 函数参数来更改渐变的颜色。

<html>
<head>
   <style>
      .gradient {
         font-size: 3rem;
         background-image: linear-gradient(45deg, #00dbde, #fc00ff);
         -webkit-background-clip: text;
         -webkit-text-fill-color: transparent;
      }
   </style>
</head>
<body>
   <h2> Creating the <i> Gradient Neon text </i> using the CSS. </h2>
   <div class = "gradient"> Check gradient in Neon text </div>
</body>
</html>

用户学习了仅使用 HTML 和 CSS 创建霓虹灯文本。我们学习了如何从基本的霓虹灯文本创建到包含彩虹效果和闪烁效果等动画的高级霓虹灯文本。

更新于: 2023年5月5日

1K+ 浏览量

开启你的 职业生涯

通过完成课程获得认证

立即开始
广告

© . All rights reserved.