CSS 의사 요소는 기본적으로 첫 글자, 첫 줄 등과 같은 요소의 특정 부분에 대한 선택기입니다. :after 및 :before 의사 요소는 각각 요소 앞뒤에 삽입하는 데 사용할 수 있습니다.
구문
다음은 요소에서 CSS Pseudo 요소를 사용하기 위한 구문입니다 -
Selector::pseudo-element {
css-property: /*value*/;
} 예시
CSS Pseudo Elements −
의 예를 살펴보겠습니다.<!DOCTYPE html>
<html>
<head>
<style>
ol, ul {
list-style: none;
counter-reset: demo_var2;
}
ul {
counter-reset: demo_var1;
}
ol > li::before {
counter-increment: demo_var2;
content: counter(demo_var2, lower-roman) ") ";
}
li::after {
counter-increment: demo_var1;
content: " " counter(demo_var1) ". ";
}
</style>
</head>
<body>
<ul>
<li>Demo Line</li>
<ol>
<li>demo line</li>
<li>demo line</li>
</ol>
<li>Demo Line</li>
<ol>
<li>demo line</li>
<li>demo line</li>
</ol>
<li>Demo Line</li>
</ul>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

예시
CSS Pseudo Elements의 또 다른 예를 봅시다 -
<!DOCTYPE html>
<html>
<head>
<style>
::-webkit-input-placeholder { /*Support for Edge */
color: blue;
font-style: italic;
}
:-ms-input-placeholder { /*Support for Internet Explorer */
color: blue;
font-style: italic;
}
::placeholder {
color: blue;
font-style: italic;
}
</style>
</head>
<body>
<h2> Sample Form </h2>
<textarea id="desc" name="desc" rows="5" cols="33" placeholder="Type here"></textarea>
<br />
<input type="text" name="author" placeholder="author name">
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -
