CSS Pseudo Elements
Next ❯Attribute Selectors
- It always start with double colon notation(: :) like " : :pseudo-element "
Syntax
selector::pseudo-element
- Default value of selector is * , so default syntax is :
*::pseudo-element { /*css properties*/ }
- turned_in_notPseudo Elements
- : :after
- : :before
- : :first-letter
- : :first-line
- : :placeholder
- : :selection
Pseudo-elements | Description |
---|---|
: :after | Adds content after the selector element |
: :before | Adds content before the selector element |
: :first-line | Selects first-line of selector element |
: :first-letter | Selects first-letter of selector element |
<p>
<p>
First line of p </br>
2nd line of p
<p>
Sample paragraph
</p>Try below options to see comment
- Note! For : :after & : :before 'content' property must be declared
& are used only with elements having closing tags (<hr> exception)
Pseudo-elements | Description |
---|---|
: :placeholder | Selects the placeholder value |
: :selection | Selects the portion selected by a user |
The placeholder value text-color changed to orange with font-size 14px inside input
- Some browser do not support this feature
::placeholder{
color:orange;
font-size:14px;
}
: :placeholdersubject
: :placeholderclose
<!DOCTYPE html>
<html>
<head>
<title>Full CSS Code</title>
<style>
::placeholder{
color:orange;
font-size:14px;
opacity:1;
}
</style>
</head>
<body>
<input type="text" placeholder="I am placeholder text..!">
</body>
</html>
Select this text to see the effect of the ::selection
When user selects above text, its background color changed to pink with text-color red
::selection {
background-color:pink;
color:red;
}
/* For Firefox */
::-moz-selection{
background-color:pink;
color:red;
}
: :selectionsubject
: :selectionclose
<!DOCTYPE html>
<html>
<head>
<title>Full CSS Code</title>
<style>
::selection{
background-color:pink;
color:red;
}
/* For Firefox */
::-moz-selection{
background-color:pink;
color:red;
}
</style>
</head>
<body>
<p>Select this text to see the effect</p>
</body>
</html>
❮ Prev Pseudo Classes
Next ❯Attribute Selectors