Fork me on github

文字效果

多行文字垂直居中

 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
     .wrap{
        display: table;
    }
    #one{
        width: 200px;
        height: 200px;
        background: #FF9999;
        text-align: center;
        vertical-align: middle;
        display: table-cell;
    }
    </style>
</head>

<body>
    <div class="wrap">
        <div id="one">
        我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容
        </div>

</body>

</html>

 

文字特效

 

 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>文字特效</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
    </style>
  </head>
  <body>
    <div class="main"></div>
  </body>
  <script>
    var str =
      "先帝创业未半,而中道崩殂;今天下三分,益州疲弊,此诚危急存亡之秋也!";
    var words = str.split("");
    var main = document.getElementsByClassName("main")[0];

    function write() {
      if (words.length > 0) {
        var span = document.createElement("span");
        var dele = words.shift();
        var opc = 0;
        
        main.appendChild(span);
        var fade = setInterval(function () {
          opc++;
          span.style.opacity = opc / 10;
        // 文字加阴影
          // span.style.color = "transparent";
          // span.style.textShadow =
          //   "0 0 5px #57606f,0 0 10px #57606f,0 0 4px #57606f,0 0 12px #ffa502";
          span.style.filter = "blur(" + (10 / opc - 1) + "px)";
          span.innerHTML = dele;
          if (opc >= 10) {
            clearInterval(fade);
            span.style.color = "#2f3542";
          }
        }, 50);
      }
    }
    setInterval(write, 200);
  </script>
</html>

 文字前加竖线

<div class="title"><span>标题</span></div>
.title {
  position: relative;
  padding-left: 13px;
  margin: 24px 0;
}

.title:before {
  content: "";
  background-color: #3796EC;
  width: 4px;
  height: 14px;
  position: absolute;
  left: 0;
  top: 50%;
  margin-top: -8px;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
}

 

posted @ 2022-12-29 10:54  我の前端日记  阅读(14)  评论(0编辑  收藏  举报
Copyright © 2021 LinCangHai
Powered by .NET 5.0 on Kubernetes