根据::selection属性:

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>CSS改变选中文本背景色</title>
  <!--引入 element-ui 的样式,-->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <script src="https://cdn.bootcss.com/vue/2.5.16/vue.min.js"></script>
  <!-- 引入element 的组件库-->
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    #app {
      margin: 50px;
    }

    .text1,
    .text2 {
      margin-top: 10px;
      margin-bottom: 50px;
    }

    .text2::-moz-selection {
      background: red;
    }

    .text2::selection {
      background: red;
    }
  </style>
</head>

<body>
  <div id="app">
    <span>默认:</span>
    <div class="text1">
      那一低头的温柔,像一朵水莲花不胜凉风的娇羞。
    </div>
    <span>CSS改变选中文本背景色:</span>
    <div class="text2">
      你向神求助是因为你相信神,神没有回应是因为神相信你。
    </div>   
  </div>
  <script>
    new Vue({
      el: '#app',
      data() {
        return {

        }
      },
      created() {

      },
      methods: {


      }
    })
  </script>

</body>

</html>

我的一个道姑朋友
80 声望4 粉丝

星光不问赶路人,岁月不负有心人。