css 实现关闭按钮 X

.close::before {
  content: "2716";
}

然后就显示出来了

这里有个更直接的例子

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<style>
  .close {
    background: orange;
    color: red;
    border-radius: 12px;
    line-height: 20px;
    text-align: center;
    height: 20px;
     20px;
    font-size: 18px;
    padding: 1px;
    top: -10px;
    right: -10px;
    position: absolute;
}
/* use cross as close button */
.close::before {
    content: "2716";
}
</style>
<body>
  <div style="height: 100px;  100px; border: 1px solid black; position: relative;">
    <span class="close"></span>
</div>
</body>
</html>

  

原文地址:https://www.cnblogs.com/aiyr/p/6897553.html