CSS - Background

김석환·2020년 10월 19일
1

CSS

목록 보기
7/18
post-thumbnail

Background 관련 속성은 해당 요소의 배경으로 이미지나 색상을 정의한다.

1. background-image 속성

요소에 배경 이미지를 지정한다.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body{
          background-image: url("./html.png");
        }
    </style>
    <title>Document</title>
</head>
<body>
</body>
</html>

2. background-repeat 속성

배경 이미지의 반족을 지정한다. 수직 수평의 반복을 지정할 수 있다.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body{
          background-image: url("./html.png");
          background-repeat: repeat-x;
        }
    </style>
    <title>Document</title>
</head>
<body>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body{
          background-image: url("./html.png");
          background-repeat: repeat-y;
        }
    </style>
    <title>Document</title>
</head>
<body>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body{
          background-image: url("./html.png");
          background-repeat: no-repeat;
        }
    </style>
    <title>Document</title>
</head>
<body>
</body>
</html>

3.background-size 속성

배경 이미지의 사이즈를 지정한다.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body{
          background-image: url("./html.png");
          background-repeat: no-repeat;
          background-size: 700px 500px;
        }
    </style>
    <title>Document</title>
</head>
<body>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body{
          background-image: url("./html.png");
          background-repeat: no-repeat;
          background-size: cover;
        }
    </style>
    <title>Document</title>
</head>
<body>
</body>
</html>

0개의 댓글