pseudo element css code example
Example 1: pseudo class css
.element:nth-child(1)
.element:hover
.element:visited
Example 2: the syntax of pseudo-class in css
The syntax of pseudo-classes:
selector:pseudo-class {
property:value;
}
Example 3: after in css
span[data-descr] {
position: relative;
text-decoration: underline;
color: #00F;
cursor: help;
}
span[data-descr]:hover::after,
span[data-descr]:focus::after {
content: attr(data-descr);
position: absolute;
left: 0;
top: 24px;
min-width: 200px;
border: 1px #aaaaaa solid;
border-radius: 10px;
background-color: #ffffcc;
padding: 12px;
color: #000000;
font-size: 14px;
z-index: 1;
}
Example 4: pseudo elements css
::after Matches a stylable element appearing after the originating element's actual content.
::before Matches a stylable element appearing before the originating element's actual content.
::first-letter Matches the first letter of the element.
::first-line Matches the first line of the containing element.
::grammar-error Matches a portion of the document containing a grammar error as flagged by the browser.
::marker Matches the marker box of a list item, which typically contains a bullet or number.
::selection Matches the portion of the document that has been selected.
::spelling-error Matches a portion of the document containing a spelling error as flagged by the browser.
Example 5: pseudo elements css
psuedo element(An intuitive answer):
keywords added to selectors (which are followed by
colon ':' or double colon '::') which allow to target
specific element (or specific part of element).
example:
you can style the first letter of a paragraph as-> p:first-letter{}
STRONG NOTE: Keep in mind that ::first-line pseudo-element must be applied
to block level (elements which break line on use)
elements in order to take effect.
Example 6: css pseudo classes
a:link {
color: #FF0000;
}
a:visited {
color: #00FF00;
}
a:hover {
color: #FF00FF;
}
a:active {
color: #0000FF;
}