CSS ๋ณํ ํจ๊ณผ๋ ์์๋ฅผ ํ์ , ์ด๋, ํฌ๊ธฐ, ๊ธฐ์ธ๊ธฐ ์กฐ์ ๋ฑ์ ๋ณํ์ ์ ์ฉํ๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค.
transform ์์ฑ
2์ฐจ์ ์ขํ ์ด๋ํ๊ธฐ
๐ตtransform: translate()
ํจ์๋ ์์๋ฅผ ํ์ฌ ์์น์์ ์ผ์ ๊ฑฐ๋ฆฌ๋งํผ ์ด๋ํ๊ณ ์ถ์ ๋ ์ฌ์ฉ ํฉ๋๋ค.
translate(x, y)
: x์ถ๊ณผ y์ถ์ ๋์์ ์ด๋ ํฉ๋๋ค.translateX()
: x์ถ์ผ๋ก ์ด๋ ํฉ๋๋ค.translateY()
: y์ถ์ผ๋ก ์ด๋ ํฉ๋๋ค.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box {
width: 100px;
height: 100px;
background-color: red;
}
.box:hover {
transform: translate(100px, 200px);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
2์ฐจ์ ํ๋ ๋๋ ์ถ์ํ๊ธฐ
๐ตtransform: scale()
ํจ์๋ ์์๋ฅผ ํ๋ํ๊ฑฐ๋ ์ถ์ํ ์ ์์ต๋๋ค.
transform: scaleX(n)
: x์ถ ๋ฐฉํฅ์ผ๋ก n๋ฐฐ ํ๋transform: scaleY(n)
: y์ถ ๋ฐฉํฅ์ผ๋ก n๋ฐฐ ํ๋transform: scale(n, n)
: x์ถ, y์ถ ๋ฐฉํฅ์ผ๋ก n๋ฐฐ ํ๋
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box {
position: absolute;
left: 100px;
top: 150px;
width: 100px;
height: 100px;
background-color: red;
}
.box:hover {
transform: scaleX(2);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
.box:hover {
transform: scale(2,2);
}
2์ฐจ์ ๊ธฐ์ธ์ด๊ธฐ
๐ต transform: skew(n deg, n deg);
๋ ์์๋ฅผ ๊ธฐ์ธ์
๋๋ค.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box {
position: absolute;
left: 100px;
top: 150px;
width: 100px;
height: 100px;
background-color: red;
}
.box:hover {
transform: skew(30deg, 30deg);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
2์ฐจ์ ํ์ ํ๊ธฐ
๐ต transform: rotate(n deg);
๋ ์์๋ฅผ ํ์ ์ํต๋๋ค.
๐ต ์ธ์๋ก ๊ฐ๋๋ฅผ ๋ฃ๋๋ฐ ์์๊ฐ์ ๋ฃ์ผ๋ฉด ์ค๋ฅธ์ชฝ์ผ๋ก ํ์ ํ๊ณ , ์์๊ฐ์ ๋ฃ์ผ๋ฉด ์ผ์ชฝ์ผ๋ก ํ์ ํฉ๋๋ค.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box {
position: absolute;
left: 100px;
top: 150px;
width: 100px;
height: 100px;
background-color: red;
}
.box:hover {
transform: rotate(45deg);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
transform-origin ์์ฑ
๐ต rotate() ํจ์๋ ์์๊ฐ ํ์ ํ ๋ ์์์ ์ค์ฌ์ ๊ธฐ์ค์ผ๋ก ํ์ ํฉ๋๋ค.
๐ต ๋ณํ ๊ด๋ จ ์์ฑ๊ฐ๋ค์ ํญ์ ๊ธฐ์ค์ ์ ๊ฐ์ง๊ณ ๋ณํ์ ํฉ๋๋ค.
๐ต ๊ทธ๋์ ๊ธฐ์ค์ ์ ๋ฐ๊พธ๋ฉด ๋ณํ ํจ๊ณผ๊ฐ ๋ค๋ฅด๊ฒ ์ ์ฉ ๋ฉ๋๋ค.
transform-origin: [x์ถ ์์น] [y์ถ ์์น];
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>๋ณํํจ๊ณผ</title>
<style>
.container {
border: 1px solid black;
display: inline-block;
margin: 20px;
}
.box {
width: 100px;
height: 100px;
background-color: red;
}
.box:hover {
transform: rotate(30deg); /* ์ค๋ฅธ์ชฝ์ผ๋ก 30๋ ํ์ */
transform-origin: top left; /* ์ผ์ชฝ ์ ๋ชจ์๋ฆฌ ๊ธฐ์ค์ ์ง์ */
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
'๐จ Frontend > HTML & CSS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
CSS โญ โฅ flex ๋ฐ์ค ๋ ์ด์์ (0) | 2023.03.16 |
---|---|
CSS โค ์น ํฐํธ, ์์ด์ฝ ํฐํธ ์ฌ์ฉํ๊ธฐ + ์ค์ต์์ (0) | 2023.03.16 |
CSS โฃ ์ ํ ํจ๊ณผ - (2) ์ ๋๋ฉ์ด์ ์์ฑ (2) | 2023.03.15 |
CSS โฃ ์ ํ ํจ๊ณผ - (1) transition, ์ค์ต ์์ (์ผํ๋ชฐ ์ํ ๋ชฉ๋ก) (2) | 2023.03.15 |
CSS โญ โข ํ์ ์์ฑ - (3) ์ฐ์ต ๋ฌธ์ (2) | 2023.03.15 |