查看: 130|回复: 5

[文章教程] 几个实用的CSS效果-文字镂空/渐变/立体/垂直/光影掠过。。。

[复制链接]
xuanxiao 发表于 2024-7-6 10:31:43 | 显示全部楼层 |阅读模式
微信图片_20240706104726.jpg
文字镂空
微信图片_20240706103245.png

  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="UTF-8">
  5.     <title>css镂空文字</title>
  6.     <style type="text/css">
  7.       div {
  8.         margin: 10% auto;
  9.         font-size: 56px;
  10.         font-weight: bold;
  11.         text-align: center;
  12.         /*字体粗细*/
  13.         -webkit-text-stroke: 1px #aa55ff;
  14.         /*描边*/
  15.         -webkit-text-fill-color: transparent;
  16.       }
  17.     </style>
  18.   </head>
  19.   <body>
  20.     <div>关注雪天前端</div>
  21.   </body>
  22. </html>
复制代码
 楼主| xuanxiao 发表于 2024-7-6 10:35:00 | 显示全部楼层
渐变文字
微信图片_20240706103245.png

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <title>线性渐变的文字</title>
  6.   <style>
  7.     div{
  8.        margin: 10% 0;
  9.        text-align: center;
  10.        font-size: 50px;
  11.        background:-webkit-linear-gradient(top, #ff007f, #aaaaff);/*线性渐变*/
  12.        -webkit-background-clip: text;
  13.        -webkit-text-fill-color: transparent;/*文字的填充颜色 透明色*/
  14.     }
  15.   </style>
  16. </head>
  17. <body>
  18.   <div>
  19.     关注雪天前端
  20.   </div>
  21. </body>
  22. </html>
复制代码
 楼主| xuanxiao 发表于 2024-7-6 10:36:11 | 显示全部楼层
立体文字
微信图片_20240706103718.bmp
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="UTF-8">
  5.     <title>立体文字</title>
  6.     <style>
  7.       body{
  8.         background-color: #333;
  9.       }
  10.       div {
  11.         color: #ffffff;
  12.         font-size: 60px;
  13.         font-weight: 700;
  14.         text-shadow: 1px 0px #ff5500, 1px 2px #ff5500, 3px 1px #ffaa00,
  15.           2px 3px #ff5500, 4px 2px #ffaa00, 4px 4px #ff5500,
  16.           5px 3px #ffaa00, 5px 5px #ff5500, 7px 4px #ffaa00,
  17.           6px 6px #ff5500, 8px 5px #ffaa00, 7px 7px #ff5500,
  18.           9px 6px #ffaa00, 9px 8px #ff5500, 11px 7px #ffaa00
  19.       }
  20.     </style>
  21.   </head>
  22.   <body>
  23.     <div>雪天前端</div>
  24.   </body>
  25. </html>
复制代码


 楼主| xuanxiao 发表于 2024-7-6 10:37:18 | 显示全部楼层
图片嵌入文字

微信图片_20240706103718.bmp
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="UTF-8">
  5.     <title>文字图案填充</title>
  6.     <style>
  7.       div {
  8.         margin: 20px;
  9.         font-size: 50px;
  10.         font-weight: bold;
  11.         background-image: url("https://img2.baidu.com/it/u=118187512,3642343065&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=300");
  12.         -webkit-background-clip: text;
  13.         -webkit-text-stroke: 1px #ff5500;
  14.         -webkit-text-fill-color: transparent;
  15.       }
  16.     </style>
  17.   </head>
  18.   <body>
  19.     <div>关注雪天前端</div>
  20.   </body>
  21. </html>
复制代码
 楼主| xuanxiao 发表于 2024-7-6 10:39:54 | 显示全部楼层
光影掠过文字

微信图片_20240706103718.bmp
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="UTF-8">
  5.     <title>实现文字的舞台灯光效果</title>
  6.     <style>
  7.       body {
  8.         background: #000;
  9.         padding-top: 10%;
  10.       }

  11.       p {
  12.         font-size: 70px;
  13.         text-align: center;
  14.         background: -webkit-linear-gradient(left, #ff5500, #ffff00) 0 0 no-repeat;
  15.         -webkit-background-size: 140px;
  16.         -webkit-background-clip: text;
  17.         -webkit-text-fill-color: rgba(255, 255, 255, 0.2);
  18.         -webkit-animation: dh 2.5s infinite;
  19.       }

  20.       @-webkit-keyframes dh {
  21.         0% {
  22.           background-position: 0 0;
  23.         }

  24.         100% {
  25.           background-position: 100% 100%;
  26.         }
  27.       }
  28.     </style>
  29.   </head>
  30.   <body>
  31.     <p>关注我的人都会大吉大利</p>
  32.   </body>
  33. </html>
复制代码



垂直文字
微信图片_20240706103245.png
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="UTF-8">
  5.     <title>垂直文本</title>
  6.     <style type="text/css">
  7.       div {
  8.         margin: 10px auto;
  9.         padding: 30px 50px;
  10.         background: #000000;
  11.         font-size: 32px;
  12.         color: #989898;
  13.         text-align: center;
  14.         writing-mode: vertical-rl;
  15.         line-height: 55px;
  16.       }
  17.     </style>
  18.   </head>
  19.   <body>
  20.     <div>
  21.       <h4>《念奴娇·赤壁怀古》苏轼</h4>
  22.       <p>

  23.         大江东去,浪淘尽,千古风流人物。<br>

  24.         故垒西边,人道是,三国周郎赤壁。<br>

  25.         乱石穿空,惊涛拍岸,卷起千堆雪。<br>

  26.         江山如画,一时多少豪杰。<br>

  27.         遥想公瑾当年,小乔初嫁了,雄姿英发。<br>

  28.         羽扇纶巾,谈笑间,樯橹灰飞烟灭。<br>

  29.         故国神游,多情应笑我,早生华发。<br>

  30.         人生如梦,一尊还酹江月。<br>
  31.       </p>
  32.     </div>
  33.   </body>
  34. </html>
复制代码




 楼主| xuanxiao 发表于 2024-7-6 10:42:13 | 显示全部楼层
打字机效果

微信图片_20240706103245.png
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="UTF-8">
  5.     <title>css打字机效果</title>
  6.     <style>
  7.       body {
  8.         height: 100vh;
  9.         background-color: #000;
  10.         overflow: hidden;
  11.         display: flex;
  12.         justify-content: center;
  13.         align-items: center;
  14.       }

  15.       .text {
  16.         width: 680px;
  17.         border-right: 2px solid #eee;
  18.         font-size: 28px;
  19.         text-align: center;
  20.         white-space: nowrap;
  21.         overflow: hidden;
  22.         background: #fff;
  23.         -webkit-background-clip: text;
  24.         /* 背景透明 */
  25.         -webkit-text-fill-color: transparent;
  26.       }

  27.       .useAnimation {
  28.         animation: dh 4s steps(44) 1s normal both,
  29.           ss 0.5s steps(44) infinite normal;
  30.       }

  31.       @keyframes dh {
  32.         from {
  33.           width: 0;
  34.         }

  35.         to {
  36.           width: calc(690px / 2);
  37.         }
  38.       }

  39.       /* 竖线的闪烁效果 */
  40.       @keyframes ss {
  41.         from {
  42.           /* 竖线的颜色 */
  43.           border-right-color: #363636;
  44.         }

  45.         to {
  46.           /* 竖线的颜色 */
  47.           border-right-color: #ffffff;
  48.         }
  49.       }
  50.     </style>

  51.   </head>
  52.   <body>
  53.     <body>
  54.       <p class="text useAnimation">
  55.         关注雪天前端,订阅更多好文
  56.       </p>
  57.     </body>

  58.   </body>
  59. </html>
复制代码


斜角标签
微信图片_20240706103245.png
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3.   <head>
  4.     <meta charset="UTF-8">
  5.     <title>Document</title>
  6.     <style>
  7.       .box {
  8.         width: 300px;
  9.         height: 400px;
  10.         background-color: cadetblue;
  11.         position: relative;
  12.         overflow: hidden;
  13.       }

  14.       .tag {
  15.         position: absolute;
  16.         top: 5%;
  17.         right: -21px;
  18.         width: 100px;
  19.         line-height: 20px;
  20.         text-align: center;
  21.         font-size: 13px;
  22.         color: #fff;
  23.         background-color: #ff0000;

  24.         transform: rotate(45deg);
  25.       }
  26.     </style>
  27.   </head>
  28.   <body>
  29.     <div class="box">
  30.       <div class="tag">推荐视频</div>
  31.     </div>
  32.   </body>
  33. </html>
复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表

在线客服

售前咨询
售后咨询
服务热线
023-58418553
微信公众号