【问题标题】:How to change the background color from selected text如何更改选定文本的背景颜色
【发布时间】:2011-04-21 17:47:44
【问题描述】:

如何更改所选文本的背景颜色?喜欢选择这个问题,但不是蓝色背景和白色文本,而是白色背景和红色、蓝色、白色等文本。
谢谢,大众汽车

【问题讨论】:

    标签: html css background selection


    【解决方案1】:

    您可以使用::selection CSS 来实现这一点。 例如:

    ::selection {
      background:#fff;
      color:red;
    }
    

    【讨论】:

      【解决方案2】:

      在 CSS3 中,您可以使用 ::selection 声明。

      ::selection { background: #00FF00; }
      

      【讨论】:

      • 如果我按 Tab 选择文本字段,仍然有一个 lue 背景。感谢您的回复,大众汽车
      【解决方案3】:

      有很多方法,但最简单的都是使用 CSS。阅读 CSS background-color 和 CSS3 hover。

      【讨论】:

        【解决方案4】:

        html,body{
          background-color: #fff;
        }
        h1,p{
          color: #000;
        }
        ::selection{
          background-color: #000;
          color: #fff;
        }
        <html>
        <head>
        <title> Trial </title>
        </head>
        <body>
          <h1> This is the trial header</h1>
          <p> This is the trial paragraph </p>
        
        </body>
        </html>

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-11
          • 2011-08-10
          • 2020-01-10
          • 2018-12-25
          • 2013-05-20
          • 1970-01-01
          相关资源
          最近更新 更多