JAYbranding

Sticky CSS

<code readonly="true"> <xmp>.sticky { position: sticky; top: 0; background-color: #0ebac5; color: white; text-transform: capitalize; text-align: center; font-size: 1.2rem; display: grid; place-content: center; } </xmp> </code> </pre> <p>이것은 페이지를 더 길게 만들기 위한 샘플 콘텐츠입니다 위의 방법은 부모 컨테이너에 스크롤할 수 있는 충분한 높이가 있을 때만 작동합니다 . , , , , , , , , , , , , , , , 컨테이너 내부에서 sticky를 적용하되 전체 페이지에 사용하려면 JavaScript를 사용해야 합니다. <pre data-line=""> <code readonly="true"> <xmp><style> body { height: 2000px; / Just for demonstration / } .fixed { position: relative; / Initially relative position / top: 0; / To keep the div at the top / width: 200px; / Adjust width as needed / height: 100px; / Adjust height as needed / background-color: lightblue; border: 1px solid blue; } .fixed.fixed-position { position: fixed; / Apply fixed position when scrolled / } </style> Fixed Div </xmp> </code> </pre> <style> .fixed { position: relative; / Initially relative position / bottom: 0; / To keep the div at the top / width: 200px; / Adjust width as needed / height: 100px; / Adjust height as needed / background-color: red; border: 1px solid blue; } .fixed.fixed-position { position: fixed; / Apply fixed position when scrolled / } </style> Fixed Div