>  기사  >  웹 프론트엔드  >  순수 CSS에서 여러 개의 고정 요소를 서로 쌓을 수 있나요?

순수 CSS에서 여러 개의 고정 요소를 서로 쌓을 수 있나요?

DDD
DDD원래의
2024-11-01 02:00:02804검색

Can we Stack Multiple Sticky Elements on Top of Each Other in Pure CSS?

순수 CSS에서 다중 스택 절대 위치 고정 요소 구현

질문:

순수 CSS에서 가능합니까? 여러 개의 끈적한 요소를 서로 쌓으시겠습니까?

예:

https://webthemez.com/demo/sticky-multi-header-scroll/index.html

사용을 선호합니다 JavaScript 구현이 아닌 순수 CSS입니다. 여러 개의 끈적끈적한 요소를 시도해 보았지만 다른 끈적한 요소를 압착하는 것을 막을 수는 없습니다. 동일한 스태킹 컨텍스트(

#sticky .sticky-1,
#sticky .sticky-2
{
  position: sticky;
}
#sticky .sticky-1
{
  top: 1em;
  z-index: 1;
}
#sticky .sticky-2
{
  top: 2em;
  z-index: 1;
}

)에 넣으려고 했지만 아래 .html 스니펫에서 볼 수 있듯이 작동하지 않았습니다. 어떤 통찰력이라도 대단히 감사하겠습니다!

<code class="html"><div id="container">
  <article id="sticky">
    <header>
    </header>
    <main>
      <h1 class="sticky-1">Sticky heading</h1 >
      <p>here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes here. </p>
    </main>
    <section>
      <h2 class="sticky-2">Both headings should stick at the same time.</h2 ></code>

위 내용은 순수 CSS에서 여러 개의 고정 요소를 서로 쌓을 수 있나요?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.