content-visibility
Baseline
2024
*
Newly available
Since 2024ë 9ì, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
* Some parts of this feature may have varying levels of support.
content-visibility CSS ìì±ì ììê° ê°ì§ ì½í
ì¸ ë¥¼ 모ë ë ëí ì§ ì¬ë¶ë¥¼ ì ì´íë©°, ê°ë ¥í ë
ë¦½ì± ê·ì¹ì íµíì¬ ì¬ì©ì ìì´ì í¸ê° í° ê·ëª¨ì ë ì´ìì ë° ë ëë§ì íìë¡ í ëê¹ì§ ì´ ìì
ì ì ì¬ì ì¼ë¡ ìëµí ì ìëë¡ í©ëë¤. ì´ë ì¬ì©ì ìì´ì í¸ê° ììì ë ëë§ ìì
(ë ì´ììê³¼ íì¸í
ì í¬í¨í)ì íìë¡ í ëê¹ì§ë ìëµí ì ìê² í´ì£¼ë©° ì´ë¡ ì¸í´ ì´ê¸° íì´ì§ë¥¼ ë¶ë¬ì¤ë ìë를 ë ë¹ ë¥´ê² í©ëë¤.
ì°¸ê³ :> contentvisibilityautostatechange ì´ë²¤í¸ëcontent-visibility: auto ê° ì ì©ë ì´ë í ììë ë ëë§ ìì
ì´ ìëµë기 ììíê±°ë ëë ëì ë°ìí©ëë¤. ì´ë ì í리ì¼ì´ì
ì½ëì ë ëë§ ì ì°¨ê° íìíì§ ìì ë (ìì, <canvas> ì 그림ì 그리ë ê²½ì°) ì´ ìì
ì ììíê±°ë ì¤ë¨íì¬ ì²ë¦¬ ë¥ë ¥ì ìµì íí ì ìë í¸ë¦¬í ë°©ë²ì ì ê³µí©ëë¤.
ìëí´ ë³´ê¸°
content-visibility: visible;
content-visibility: hidden;
<section class="default-example" id="default-example">
<div class="container" id="example-element">
<div class="child">
<span>This is an inner div</span>
</div>
</div>
</section>
.container {
width: 140px;
height: 140px;
border: 3px solid rgb(64, 28, 163);
background-color: rgb(135, 136, 184);
display: flex;
align-items: center;
justify-content: center;
}
.child {
border: 3px solid rgb(64, 28, 163);
background-color: wheat;
color: black;
width: 80%;
height: 80%;
display: flex;
align-items: center;
justify-content: center;
}
구문
/* í¤ìë ê° */
content-visibility: visible;
content-visibility: hidden;
content-visibility: auto;
/* ì ì ê° */
content-visibility: inherit;
content-visibility: initial;
content-visibility: revert;
content-visibility: revert-layer;
content-visibility: unset;
ê°
visible-
ìë¬´ë° í¨ê³¼ë ë°ìíì§ ììµëë¤. ììì ì½í ì¸ ë íë²íê² ë ëë©ëë¤.
-
ììê° í´ë¹ ììì 컨í ì¸ ë¥¼ ìëµí©ëë¤. ìëµë ì½í ì¸ ë íì´ì§ ë´ ì°¾ê¸°ë íì ìí ë¤ë¹ê²ì´ì ë± ì¬ì©ì ìì´ì í¸ í¹ì±ì ì ê·¼í ì ìê³ , ì íëê±°ë í¬ì»¤ì¤ë ìë ììµëë¤. ììì
display: noneê° ì ì©ë ê²ê³¼ ì ì¬í©ëë¤. auto-
ììë ë ì´ìì 격리, ì¤íì¼ ê²©ë¦¬, íì¸í¸ 격리를 íì±íí©ëë¤. ë§ì¼ ììê° ì¬ì©ìì ê´ê³ê° ìë¤ë©´, ì´ ìì ìì를 ìëµí©ëë¤. hiddenê³¼ë ë¤ë¥´ê², ìëµë ììë ì¬ì í íì´ì§ ë´ ì°¾ê¸°ë íì ìí ë¤ë¹ê²ì´ì ë± ì¬ì©ì ìì´ì í¸ í¹ì±ì ì ê·¼ì´ ê°ë¥íë©°, íë²íê² ì íëê±°ë í¬ì»¤ì¤ë ê°ë¥í©ëë¤.
ì¤ëª
>content-visibility ìì±ì ì ëë©ì´ì ê³¼ ì í ì ì©í기
ì§ìíë ë¸ë¼ì°ì ë ë ë¹ì°ì ì ëë©ì´ì
íì
ì ë³íì ì¬ì©íì¬ content-visibility 를 ì ëë©ì´ì
/ì íí©ëë¤.
ë¹ì°ì ì ëë©ì´ì
ì ì¼ë°ì ì¼ë¡ ìì±ì´ ì ëë©ì´ì
ì´ ì§íëë ì¤ê° ì§ì 50% ìì ë ê°ì§ ê° ì¬ì´ë¥¼ ì¦ê°ì ì¼ë¡ ì ííë¤ë ê²ì ì미í©ëë¤. íì§ë§ content-visibility 를 ì¬ì©íë ê²½ì°ìë ë¸ë¼ì°ì ë ì ì²´ ì ëë©ì´ì
ì§ì ìê° ëì ì ëë©ì´ì
ì½í
ì¸ ë¥¼ ë³´ì¬ì£¼ê¸° ìí´ ë ê° ì¬ì´ë¥¼ ì íí©ëë¤. ìì를 íì¸í´ ë³´ì¸ì.
content-visibilityê°hiddenììvisibleë¡ ì íëë¤ë©´, ì ëë©ì´ì ì0%ìì ìì ê°ì´visibleë¡ ì íëì´ ì ëë©ì´ì ì´ ì§íëë ëì ë´ì©ì´ ë³´ì´ê² ë©ëë¤.content-visibilityê°visibleììhiddenì¼ë¡ ì íëë¤ë©´, ì ëë©ì´ì ì100%ìì ìì ê°ì´hiddenì¼ë¡ ì íëì´ ì ëë©ì´ì ì´ ì§íëë ëì ë´ì©ì´ ë³´ì´ê² ë©ëë¤.
ì´ ëìì DOMìì content-visibility: hidden 를 ì¬ì©íì¬ ìì를 ì ê±°íë ì§ì
ì ì´ë ë§ë¬´ë¦¬ ì ëë©ì´ì
ì ìì±í ë ì´ë¥¼ ì¦ê°ì ì¼ë¡ ì¬ë¼ì§ê² íë ëì ë¶ëë¬ì´ ì í(íì´ë ìì ë±) ì í ëì ë ì ì©íê² ì¬ì©ë©ëë¤.
content-visibility 를 CSS ì íê³¼ í¨ê» ì ëë©ì´ì
íí ë, transition-behavior: allow-discrete ê° content-visibility ì ì¤ì ì´ ëì´ ìì´ì¼ í©ëë¤. ì´ë content-visibility ì íì í¨ê³¼ì ì¼ë¡ ëìíê² í©ëë¤.
ì°¸ê³ :
ììì content-visibility ê°ì ì íí ë, display 를 ì íí ëì²ë¼ @starting-style ë¸ë¡ì ì¬ì©íì¬ ì íì ìì ê°ì ì ê³µí íìê° ììµëë¤. ì´ë content-visibility ê° display ì²ë¼ DOMìì ìì를 ì¨ê¸°ì§ ìê³ ììì ì½í
ì¸ ë ëë§ì ìëµí기 ë문ì
ëë¤.
íì ì ì
| ì´ê¸°ê° | visible |
|---|---|
| ì ì©ëì | elements for which size containment can apply |
| ìì | no |
| ê³ì° ê° | as specified |
| Animation type | Discrete behavior except when animating to or from hidden is visible for the entire duration |
íì 구문
content-visibility =
visible |
auto |
hidden
ì ê·¼ì±
content-visibility: auto ìì±ì´ ì ì©ë íë©´ ë°ì ì½í
ì¸ ë 문ì ê°ì²´ 모ë¸ê³¼ ì ê·¼ì± í¸ë¦¬ ë´ì ê·¸ëë¡ ë¨ì ììµëë¤. ì´ë¥¼ íµí´ content-visibility: auto 를 ì¬ì©í´ íì´ì§ ì±ë¥ì í¥ììí¤ë©´ìë ì ê·¼ì±ì ë¶ì ì ì¸ ìí¥ì ì£¼ì§ ìì ì ììµëë¤.
íë©´ ë°ì ì½í
ì¸ ì ëí ì¤íì¼ì´ ë ëë§ëì§ ìëë¼ë, ìëì ì¼ë¡ display: none ëë visibility: hidden ì¼ë¡ ì¨ê¸´ ììë ì ê·¼ì± í¸ë¦¬ìë ì¬ì í ëíë©ëë¤.
ì ê·¼ì± í¸ë¦¬ìì ìì를 ì ê±°íë ¤ë©´ aria-hidden="true" 를 ì¬ì©íì¸ì.
ìì
>auto를 ì¬ì©íì¬ ê¸´ íì´ì§ìì ë ëë§ ë¹ì© ì¤ì´ê¸°
ë¤ì ìì ììë content-visibility: auto 를 ì¬ì©íì¬ íë©´ ë°ì ì¹ì
ì ëí´ íì¸í
ë° ë ëë§ì ìëµíë ë°©ë²ì ë³´ì¬ì¤ëë¤.
ë·°í¬í¸ìì ë²ì´ë section ì ì½í
ì¸ ë í´ë¹ ì¹ì
ì´ ë·°í¬í¸ ê·¼ì²ë¡ ì¬ ëê¹ì§ íì¸í
ì´ ê±´ëë°ì´ì§ë©°, ì´ë¥¼ íµí´ íì´ì§ ë¶ë¬ì¤ê¸°ì ìí¸ìì© ì±ë¥ì´ ê°ì ë©ëë¤.
HTML
<section>
<!-- Content for each section⦠-->
</section>
<section>
<!-- Content for each section⦠-->
</section>
<section>
<!-- Content for each section⦠-->
</section>
<!-- ⦠-->
CSS
contain-intrinsic-size ìì±ì ê°ê°ì section ììì 500pxì 기본 ëì´ì ëì´ ê°ì ì¶ê°í©ëë¤. ììê° ë ëë ì´íìë ì´ë ë·°í¬í¸ìì ì¤í¬ë¡¤ì´ ëëë¼ë ìëì í¬ê¸°ë¥¼ ì ì§í©ëë¤.
section {
content-visibility: auto;
contain-intrinsic-size: auto 500px;
}
ê°ìì±ì ìí hidden ì¬ì©í기
ë¤ì ìì ë ì½í
ì¸ ì ê°ìì±ì JavaScript를 ì´ì©íì¬ ê´ë¦¬íë ìì ì
ëë¤.
display: none; ì ì¬ì©íë ëì content-visibility: hidden; 를 ì¬ì©íë©´ ì¨ê²¨ì§ ìíììë ì½í
ì¸ ì ë ëë§ ìí를 ì ì§íë©°, ë ëë§ ìëê° ë ë¹ ë¦
ëë¤.
HTML
<div class="hidden">
<button class="toggle">Show</button>
<p>ì´ ì½í
ì¸ ë ì´ê¸°ìë ì¨ê²¨ì ¸ ìì§ë§ ë²í¼ì í´ë¦íì¬ ë³¼ ì ììµëë¤.</p>
</div>
<div class="visible">
<button class="toggle">Hide</button>
<p>ì´ ì½í
ì¸ ë ì´ê¸°ìë ë³´ì´ì§ë§ ë²í¼ì í´ë¦íì¬ ì¨ê¸¸ ì ììµëë¤.</p>
</div>
CSS
content-visibility ìì±ì visible ê³¼ hidden í´ëì¤ê° ì ì©ë ììì ì§ì ììì¸ ë¨ë½ë¤ì ì¤ì ë©ëë¤. ì´ ìì ììë ë¶ëª¨ div ììì ì ì©ë CSS í´ëì¤ì ë°ë¼ ë¨ë½ ë´ì ì½í
ì¸ ê° ë³´ì´ê±°ë ì¨ê²¨ì§ ì ììµëë¤.
contain-intrinsic-size ìì±ì ì½í
ì¸ ì í¬ê¸°ë¥¼ ëíë´ê¸° ìí´ í¬í¨ëììµëë¤. ì´ë ì½í
ì¸ ê° ì¨ê²¨ì§ ë ë ì´ìì ê¹ë¹¡ìì ìµìíí©ëë¤.
p {
contain-intrinsic-size: 0 1.1em;
border: dotted 2px;
}
.hidden > p {
content-visibility: hidden;
}
.visible > p {
content-visibility: visible;
}
JavaScript
const handleClick = (event) => {
const button = event.target;
const div = button.parentElement;
button.textContent = div.classList.contains("visible") ? "Show" : "Hide";
div.classList.toggle("hidden");
div.classList.toggle("visible");
};
document.querySelectorAll("button.toggle").forEach((button) => {
button.addEventListener("click", handleClick);
});
ê²°ê³¼
content-visibilityì ì ëë©ì´ì ì ì©í기
ì´ ìì ììë í´ë¦íê±°ë ì무 í¤ë¥¼ ëë¬ ë³´ì´ê±°ë ë³´ì´ì§ ìê² ëë í ê¸ ì½í
ì¸ ë¥¼ ê°ì§ <div> ììê° ì¡´ì¬í©ëë¤.
HTML
<p>
íë©´ì ì무 ê³³ì í´ë¦íê±°ë ì무 í¤ë¥¼ ëë¬
<code><div></code> ì½í
ì¸ ê° ë³´ì¬ì§ê±°ë ì¨ê²¨ì§ë í ê¸ì ëìíê²
í´ë³´ì¸ì.
</p>
<div>
ì¬ê¸° ì ëë©ì´ì
<code><div></code> ììê° ì¡´ì¬í©ëë¤.
<code>content-visibility: hidden;</code> 그리ê³
<code>content-visibility: visible;</code>. í
ì¤í¸ ììì ë¶ëë¬ì´ ì ëë©ì´ì
í¨ê³¼ë¥¼ ìì±í©ëë¤.
</div>
CSS
CSSììë <div> ì ì´ê¸°ì content-visibility: hidden; 를 ì ì©íì¬ ì½í
ì¸ ë¥¼ ì¨ê¹ëë¤. ê·¸ë¦¬ê³ @keyframe ì ëë©ì´ì
ì ì¤ì íê³ , ì´ë¡ ì¸í´ <div> ê° ë³´ì´ê±°ë ì¨ê²¨ì§ ì ìëë¡ í´ëì¤ì ì¶ê°í©ëë¤. ì´ ê³¼ì ìì content-visibility ì ììì ì ëë©ì´ì
ííì¬ ì½í
ì¸ ê° ë³´ì´ê±°ë ì¨ê²¨ì§ ë ë¶ëë¬ì´ ì ëë©ì´ì
í¨ê³¼ë¡ ëìí ì ìê² í©ëë¤.
div {
font-size: 1.6rem;
padding: 20px;
border: 3px solid red;
border-radius: 20px;
width: 480px;
content-visibility: hidden;
}
/* ì ëë©ì´ì
í´ëì¤ */
.show {
animation: show 0.7s ease-in forwards;
}
.hide {
animation: hide 0.7s ease-out forwards;
}
/* ì ëë©ì´ì
í¤íë ì */
@keyframes show {
0% {
content-visibility: hidden;
color: rgb(0 0 0 / 0%);
}
100% {
content-visibility: visible;
color: rgb(0 0 0 / 100%);
}
}
@keyframes hide {
0% {
content-visibility: visible;
color: rgb(0 0 0 / 100%);
}
100% {
content-visibility: hidden;
color: rgb(0 0 0 / 0%);
}
}
JavaScript
JavaScript를 ì¬ì©íì¬ .show ë° .hide í´ëì¤ë¥¼ <div> ì ì ì íê² ì ì©íì¬ ë³´ì´ê±°ë ì¨ê²¨ì§ë ìí를 í ê¸í ì ìë ì ëë©ì´ì
ì 구íí©ëë¤.
const divElem = document.querySelector("div");
const htmlElem = document.querySelector(":root");
htmlElem.addEventListener("click", showHide);
document.addEventListener("keydown", showHide);
function showHide() {
if (divElem.classList[0] === "show") {
divElem.classList.remove("show");
divElem.classList.add("hide");
} else {
divElem.classList.remove("hide");
divElem.classList.add("show");
}
}
ê²°ê³¼
íë©´ì ë ëë ê²°ê³¼ë ë¤ìê³¼ ê°ìµëë¤.
ëª ì¸ì
| Specification |
|---|
| CSS Containment Module Level 2 > # content-visibility > |