Reputation: 151
How can I change the background color from selected text? Like selecting this question but instead of a blue background and white text, a white background and red, blue, white etc. text.
Thanks, VVW
Upvotes: 1
Views: 3563
Reputation: 1162
It can be done with the::selection
CSS pseudo-element.
for example:
p::selection {
background:red;
}
Upvotes: 0
Reputation: 63
You can use ::selection
CSS to achieve this.
Eg:
::selection {
background:#fff;
color:red;
}
Upvotes: 3
Reputation: 743
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>
Upvotes: 0
Reputation: 8694
There are many ways, but the easiest all use CSS. Read up on CSS background-color and CSS3 hover.
Upvotes: 0
Reputation: 22605
In CSS3, you can use the ::selection
declaration.
::selection { background: #00FF00; }
Upvotes: 1