::before
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 7ì.
CSSìì, ::before ë ì íë ììì 첫ë²ì§¸ ììì¸ ìì¬ ìì를 ìì±í©ëë¤. ì´ë ì¢
ì¢
content ìì±ì íì©íì¬ ììì ì¥ì ì½í
ì¸ ë¥¼ ì¶ê°íë ë°ì ì¬ì©ë©ëë¤. 기본ì ì¼ë¡ ì¸ë¼ì¸ íìì
ëë¤.
ìëí´ ë³´ê¸°
a {
color: #0000ff;
text-decoration: none;
}
a::before {
content: "ð";
}
.local-link::before {
content: url("/shared-assets/images/examples/firefox-logo.svg");
display: inline-block;
width: 15px;
height: 15px;
margin-right: 5px;
}
<p>
Learning resources for web developers can be found all over the internet. Try
out
<a href="https://web.dev/">web.dev</a>,
<a href="https://www.w3schools.com/">w3schools.com</a> or our
<a href="https://developer.mozilla.org/" class="local-link">MDN web docs</a>.
</p>
ì°¸ê³ :>::before ì ::after ë¡ ìì±ë ìì¬ ììë¤ì ë§ì¹ í´ë¹ ììê° ì ì©ë ììì ì§ì ììì¸ ê²ì²ë¼ ìì±ë ë°ì¤ì
ëë¤. ì¦, ì본 ììì ì§ê³ ììì´ê¸° ë문ì <img> ì²ë¼ ì½í
ì¸ ê° CSS ìì 모ë¸ì ë²ì를 ë²ì´ëë ëì²´ ìì ìë ì ì©í ì ììµëë¤.
구문
::before {
content: /* value */;
/* properties */
}
content ìì±ì´ ì ìëì§ ììê±°ë ì í¨íì§ ìì ê°ì ê°ì§ê±°ë, ê°ì¼ë¡ normal ì´ë none ì ê°ì§ê³ ìë¤ë©´ ::before ê°ì ììë ë ëëì§ ìê³ display: none ì´ ì¤ì ë ê²ì²ë¼ ëìí©ëë¤.
Note: ì íì ë 벨 3 ììë ì½ë¡ í기ë²ì¸
::before를 ìì¬ ìì ì ìì¬ í´ëì¤ ì íëë¡ ìê°í©ëë¤. ë¸ë¼ì°ì ë ì¸ë¯¸ì½ë¡ í기ì¸:beforeë ìì©íë©°, ì´ë CSS2ìì ìê°ëì´ ììµëë¤.
ì ê·¼ì±
ì¤í¬ë¦° 리ëììë ìíí ì ê·¼ëì§ ì기 ë문ì ì½í
ì¸ ë¥¼ ì¶ê°í기 ìí´ ::before ìì¬ ìì를 ì¬ì©íë ê²ì ê¶ì¥ëì§ ììµëë¤.
ìì
>ì¸ì© íì ì¶ê°í기
ìëë ::before ìì¬ ìì를 ì¬ì©íì¬ ì¸ì© íì를 ì¶ê°íë ìì ì
ëë¤. ì¸ì© 문ì를 ì¶ê°í기 ìí´ ::before ì ::after 를 모ë ì¬ì©í©ëë¤.
HTML
<q>Some quotes</q>, he said, <q>are better than none.</q>
CSS
q::before {
content: "«";
color: blue;
}
q::after {
content: "»";
color: red;
}
ê²°ê³¼
ì¥ì ìì
content ìì± ë´ì í
ì¤í¸ë ì´ë¯¸ì§ ëí ìíëëë¡ ìì í ì ììµëë¤.
HTML
<span class="ribbon">ì¤ë ì§ì ë°ì¤ê° ì´ëì ìëì§ ë³´ì¸ì.</span>
CSS
.ribbon {
background-color: #5bc8f7;
}
.ribbon::before {
content: "ì¬ê¸° ì¤ë ì§ì ë°ì¤ê° ììµëë¤.";
background-color: #ffba10;
border-color: black;
border-style: dotted;
}
ê²°ê³¼
í¬ë 리ì¤í¸
ì´ë² ìì ììë ìì¬ ìì를 íì©íì¬ í¬ë 리ì¤í¸ë¥¼ ë§ëëë¤. ì¬ê¸°ìë ì ì ê³µì를 ë¤ì¬ UI ì ì¬ì©ì ê²½íì í¥ììì¼°ìµëë¤.
HTML
<ul>
<li>Buy milk</li>
<li>Take the dog for a walk</li>
<li>Exercise</li>
<li>Write code</li>
<li>Play music</li>
<li>Relax</li>
</ul>
CSS
li {
list-style-type: none;
position: relative;
margin: 2px;
padding: 0.5em 0.5em 0.5em 2em;
background: lightgrey;
font-family: sans-serif;
}
li.done {
background: #ccff99;
}
li.done::before {
content: "";
position: absolute;
border-color: #009933;
border-style: solid;
border-width: 0 0.3em 0.25em 0;
height: 1em;
top: 1.3em;
left: 0.6em;
margin-top: -1em;
transform: rotate(45deg);
width: 0.5em;
}
JavaScript
const list = document.querySelector("ul");
list.addEventListener(
"click",
(ev) => {
if (ev.target.tagName === "LI") {
ev.target.classList.toggle("done");
}
},
false,
);
ì ì½ëê° ì¤íë ì´íì 결과를 íì¸í ì ììµëë¤. ìë¬´ë° ìì´ì½ë ì¬ì©ëì§ ììê³ , ì²´í¬ íìë ë³´ì´ë ë°ì ê°ì´ CSS ë´ì ì¤íì¼ìì ::before ì ì¤ì ë ê²ì
ëë¤. ëª ê°ì§ ì¼ì ìë£ë¡ ì²ë¦¬í´ ë³´ì¸ì.
ê²°ê³¼
í¹ì 문ì
HTMLì´ ìëë¼ CSSë¼ë í¹ì± ë문ì ë§í¬ì ììë¤ì ì½í ì¸ ê°ì ì¬ì©í ì ììµëë¤. ë§ì¼ í¹ì 문ì를 ì¬ì©í´ì¼ íëë° CSS ì½í ì¸ ë¬¸ìì´ì ì§ì ì ë ¥í ì ìë ê²½ì°, ë°±ì¬ëìì 16ì§ì ì ëì½ë ê°ì¼ë¡ 구ì±ë ì ëì½ë ì´ì¤ì¼ì´í ìíì¤ë¥¼ ì¬ì©íììì¤.
HTML
<ol>
<li>Crack Eggs into bowl</li>
<li>Add Milk</li>
<li>Add Flour</li>
<li aria-current="step">Mix thoroughly into a smooth batter</li>
<li>Pour a ladleful of batter onto a hot, greased, flat frying pan</li>
<li>Fry until the top of the pancake loses its gloss</li>
<li>Flip it over and fry for a couple more minutes</li>
<li>serve with your favorite topping</li>
</ol>
CSS
li {
padding: 0.5em;
}
li[aria-current="step"] {
font-weight: bold;
}
li[aria-current="step"]::after {
content: " \21E6"; /* Hexadecimal for Unicode Leftwards white arrow*/
display: inline;
}
ê²°ê³¼
ëª ì¸ì
| Specification |
|---|
| CSS Pseudo-Elements Module Level 4 > # selectordef-before > |