background-position : 배경이미지 위치 지정하기



html)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, height=device-height, 
                     minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
    <title>Insert title here</title>
    <style>
    /*
    background-position: 가로기준 세로기준
    1) 값을 하나만 지정하는 경우
    left, right, 숫자 : 가로기준으로 적용, 세로기준은 center가 된다
    top, bottom : 세로기준으로 적용, 가로기준은 center가 된다
    2) %로 지정하는 경우
    해당영역의 %위치에 배경이미지의 %가 위치한다
    */
    div {
        background-position: 50% 50%;    /* 이미지가 div 태그 가운데에 오게 된다 */
    
        width: 100%;
        height: 300px;
        background-image: url(images/tile.png);
        background-repeat: no-repeat;
        border: 1px solid #000;
    }
    </style>
</head>
 
<body>
    <div></div>
</body>
</html>
cs



결과

%로 지정했으므로 이미지의 가운데(50% 50%)가 div 태그의 가운데(50% 50%)에 위치한다


+ Recent posts