728x90
๋ฐ์ํ
๐ก ์ค์ต ํฌ์ธํธ!
- position : sticky ๋ฅผ ์ด์ฉํด์ ํ๋ฉด์ ์ข์ธก์ ์์นํ ํ ์คํธ๋ ์คํฌ๋กค์ ๋ด๋ฆฌ๋ฉด ์์ง์ด๊ณ , ์ฐ์ธก์ ์ด๋ฏธ์ง๋ ๊ณ ์ ๋์ด์๋ ๋ ํนํ ๊ตฌ์กฐ์ ๋ ์ด์์์ ๋ง๋ค์ด๋ณด์๋ค.
๐ HTML
<div class="gray">
<!-- ์ผ์ชฝ: ํ
์คํธ -->
<div class="text-container">
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Sapiente expedita obcaecati ducimus, at quia nam deserunt ad atque ex cupiditate illo
itaque laboriosam molestiae dignissimos molestias minima vitae, doloremque non.
</div>
</div>
<!-- ์ค๋ฅธ์ชฝ : ์ด๋ฏธ์ง -->
<div class="image">
<img src="./img/appletv.jpg" width="100%">
</div>
<div style="clear:both;"></div>
</div>
- ์ข์ธก์ ์๋ฌด์๋ฏธ ์๋ ํ ์คํธ๋ก ์ฑ์์ฃผ๊ณ ์ค๋ฅธ์ชฝ์๋ ์ด๋ฏธ์ง๋ฅผ ๋ฃ์ด์ฃผ์๋ค.
- float ์์ฑ์ ์ฌ์ฉํ ๊ฑฐ๋ผ์ ์ค๊ฐ์ clear : both ์์ฑ์ด ๋ค์ด๊ฐ div ํ๊ทธ๋ ๋ฃ์ด์ฃผ์๋ค.
๐ CSS
.gray {
background: rgb(218, 216, 216);
height: 2550px;
margin-top: 300px;
width: 100%;
}
.text-container {
float: left;
width: 45%;
}
.text {
margin-top: 150px;
}
.image {
float: right;
width: 600px;
position: sticky;
top: 400px;
}
- ์ข์ธก์ ํด๋นํ๋ text-container ํด๋์ค๋ float : left ๋ฅผ ์ฃผ๊ณ , ์ฐ์ธก์ ํด๋นํ๋ image ํด๋์ค๋ float : right ๋ฅผ ์ฃผ์๋ค.
- ๊ฐ๊ฐ ์ ๋นํ ๋๋น๋ฅผ ์ค์ ํด ๋น์จ์ ๋ง์ถฐ์ฃผ๊ณ image ํด๋์ค์๋ง position : sticky ๋ฅผ ๋ฃ์ด์ฃผ๊ณ top ์์ฑ์ ํตํด ์์น๋ฅผ ์ง์ ํ์ฌ ๊ณ ์ ์์ผ์ฃผ์๋ค.
728x90
๋ฐ์ํ