배경

송현민·2025년 1월 6일


웹페이지를 만들다 보면 위와 같이 배경사진을 넣는 경우가 있다

오늘은 이러한 배경관련 css 속성들을 공부해볼 것이다.

1. 배경사진 넣기

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/css/back.css">
</head>
<body>
    <div class="main-background">
    </div>
</body>
</html>
/* 기본 스타일 초기화 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.main-background{
    width: 100%;
    height: 500px;
    background-image: url(/img/toss.png);
    background-size: 100%;
}

2. 반복을 없애고 싶은 경우

/* 기본 스타일 초기화 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.main-background{
    width: 100%;
    height: 500px;
    background-image: url(/img/toss.png);
    background-size: 100%;
    background-repeat: no-repeat;
}
  1. 그외 속성들
    background-size: cover;
    background-size: contain;

0개의 댓글