How to change color after select a text or line?

Asked 19-Jul-2021
Viewed 234 times

1

How to change color after select a text or line?


2 Answers


0

<!DOCTYPE html>
<html>
<head>
<style>
::-moz-selection { /* Code for Firefox */
  color: red;
  background: yellow;
}

::selection {
  color: red;
  background: yellow;
}
</style>
</head>
<body>

<h1>Select some text on this page:</h1>

<p>This is a paragraph.</p>
<div>This is some text in a div element.</div>

<p><strong>Note:</strong> ::selection is not supported in Internet Explorer 8 and earlier versions.</p>
<p><strong>Note:</strong> Firefox supports an alternative, the ::-moz-selection property.</p>

</body>
</html>

Output

How to change color after select a text or line?

2

::selection use to select a paragraph and then change the color
The ::selection pseudo-element matches the portion of an element that is selected by a user.
The following CSS properties can be applied to ::selection: color, background, cursor, and outline.
The following example makes the selected text white on a orange background:
<!DOCTYPE html>

<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title></title>
    <style>
        ::selection {
            background-color:orange;
            color:white;
        }
    </style>
</head>
<body>
    <p><strong>Note : </strong> Select some data of text</p>
    <b>Windows App Development Solution</b><br />
MindStick is examining enhanced ideas to create user interference more fertile with our enthralled windows application development services.
    Although inadequate, windows have a faithful user base, growing mobile apps for this program unleashes vast business possibilities.
     we are identified for producing reliable and results-oriented Windows Phone Apps Development solutions.
     Our Windows developer team is centered to create windows mobile apps that will deliver user experience and interaction enlightening, connected, and supportive.
</body>
</html>


Loading...
Ads