728x90
๋ฐ์ํ
๐ก ์ค์ต ํฌ์ธํธ!
- position: sticky ์์ฑ์ ํ์ฉํ์ฌ ์ฐ์ธก์ ์ด๋ฏธ์ง๋ ์์น๊ฐ ๊ณ ์ ๋๊ณ ์ข์ธก์ ํ ์คํธ๋ง ์คํฌ๋กคํ๋ฉด ์์ง์ด๋๋ก ๋ง๋ค์ด๋ณด์๋ค.
- ๋ฐ์ํ์ผ๋ก ๋ง๋ค๋ฉด ์ธ๋ก๋ก 1์ด์ด ๋์ด ํฌ๊ฒ ์๋ฏธ๊ฐ ์์ ๊ฒ ๊ฐ์์ ์์ํ๊ฒ PC ํ๋ฉด์ฉ์ผ๋ก ๋ง๋ค๊ณ ๋ฐ์ํ์ ๋ฐ๋ก ๊ณ ๋ คํ์ง ์์๋ค.
๐ HTML
- image div ํ๊ทธ๋ ์ฐ์ธก์, text div ํ๊ทธ๋ ์ข์ธก์ ๋ฐฐ์นํ ์์ ์ด๋ฉฐ ํธํ๊ฒ ๋ณด๊ธฐ ์ํด image div ํ๊ทธ๋ฅผ ์๋จ์ ์ ์๋ค. (์์๋ฅผ ๋ฐ๊พธ์ด์ ์ด๋ float ๋ฅผ ์ด์ฉํด์ ์์น ์ง์ ์ด ๊ฐ๋ฅํ๋ค.)
- float ์์ฑ์ ์ด์ฉํ์ผ๋ ์ค๊ฐ์ค๊ฐ์ div ํ๊ทธ๋ฅผ ๋ง๋ค์ด clear : both ์์ฑ์ ๋ฃ์ด์ฃผ๋ ๊ฒ๋ ๊น๋จน์ง ๋ง๊ธฐ!
<div class="grey">
<div class="image">
<img src="./img/appletv.jpg" width="100%">
</div>
<div class="text">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam, inventore ullam.
Repudiandae distinctio dolorum perspiciatis odio praesentium.
Quae amet facilis officia vel reprehenderit repellendus earum non, nihil, ab tempora autem?
</div>
<div style="clear:both"></div>
<div class="text">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam, inventore ullam.
Repudiandae distinctio dolorum perspiciatis odio praesentium.
Quae amet facilis officia vel reprehenderit repellendus earum non, nihil, ab tempora autem?
</div>
<div style="clear:both"></div>
<div class="text">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam, inventore ullam.
Repudiandae distinctio dolorum perspiciatis odio praesentium.
Quae amet facilis officia vel reprehenderit repellendus earum non, nihil, ab tempora autem?
</div>
<div style="clear:both"></div>
<div class="text">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam, inventore ullam.
Repudiandae distinctio dolorum perspiciatis odio praesentium.
Quae amet facilis officia vel reprehenderit repellendus earum non, nihil, ab tempora autem?
</div>
<div style="clear:both"></div>
<div class="text">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam, inventore ullam.
Repudiandae distinctio dolorum perspiciatis odio praesentium.
Quae amet facilis officia vel reprehenderit repellendus earum non, nihil, ab tempora autem?
</div>
<div style="clear:both"></div>
<div class="text">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam, inventore ullam.
Repudiandae distinctio dolorum perspiciatis odio praesentium.
Quae amet facilis officia vel reprehenderit repellendus earum non, nihil, ab tempora autem?
</div>
<div style="clear:both"></div>
</div>
๐ CSS
- image ๋ float : right ์์ฑ์ ์ฃผ์ด ์ฐ์ธก์ ๋ฐฐ์นํ๊ณ position : sticky ์์ฑ์ ์ด์ฉํ์ฌ ๊ณ ์ ์์ผ์ฃผ์๋ค.
- sticky ๋ฅผ ์ฌ์ฉํ ๋๋ ๊ณ ์ ํ ์ขํ(top, right, bottom, right ์ฌ์ฉ)๋ ํจ๊ป ์ ์ด์ฃผ์ด์ผ ํ๋ค.
- text ๋ float: left ์์ฑ์ ์ฃผ์ด ์ข์ธก์ ๋ฐฐ์นํ๋ค.
body {
background: #eee;
height: 2000px;
}
.grey {
height: 1600px;
margin-top: 400px;
}
.image {
float: right;
width: 600px;
position: sticky;
top: 400px;
}
.text {
margin-bottom: 200px;
float: left;
width: 600px;
}
728x90
๋ฐ์ํ
'[๊ฐ๋ฐ] Practice > HTML CSS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[HTML/CSS] ์ข ์ด์ฒ๋ผ ๋ค์งํ๋ ํ๋กํ์ฌ์ง ๋ง๋ค๊ธฐ (0) | 2022.03.02 |
---|---|
[HTML/CSS] Admin Page ๋ง๋ค๊ธฐ (0) | 2022.03.02 |
[HTML/CSS] grid-column, grid-row ์ผ๋ก ๋ ์ด์์ ๋ง๋ค๊ธฐ (0) | 2022.03.02 |
[HTML/CSS] Grid ๋ฐ์ํ ๋ ์ด์์ ๋ง๋ค๊ธฐ (0) | 2022.03.02 |
[HTML/CSS] transform & animation ์ผ๋ก ๋งค๋๋ฌ์ด ์ ๋๋ฉ์ด์ ๋ง๋ค๊ธฐ (0) | 2022.03.01 |