css视觉--漂亮的文本下划线

2018-03-23  本文已影响0人  怪兽别跑biubiubi
<!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>漂亮的文本下划线</title>
  <style>
    p {
      font-family: Arial, sans-serif;
      display: inline;
      text-shadow: 1px 1px 0 #f5f6f9, -1px 1px 0 #f5f6f9, -1px -1px 0 #f5f6f9, 1px -1px 0 #f5f6f9;
      font-size: 18px;
      background-image: linear-gradient(90deg, currentColor 100%, transparent 100%);
      background-position: 0 1em;
      background-repeat: repeat-x;
      background-size: 1px 1px;
    }
    p::-moz-selection {
      background-color: rgba(0, 150, 255, 0.3);
      text-shadow: none;
    }
    p::selection {
      background-color: rgba(0, 150, 255, 0.3);
      text-shadow: none;
    }
  </style>
</head>
<body>
  <p>
    text-shadow: ... 具有4个偏移值,覆盖4x 4 px区域,以确保下划线具有“厚”阴影,该阴影覆盖后代裁剪下划线的线。使用与背景匹配的颜色。对于较大字体,请使用较大字体px 大小。
    background-image: linear-gradient(...) 使用当前文本颜色(currentColor )创建90度渐变 .
    background-* 属性将渐变的大小设置为1x1px,并沿x轴重复。
    ::selection 伪选择器确保文本阴影不会干扰文本选择。
  </p>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读