[Frontend] CSS, @media와 transition

Transition Example

HTML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html>

<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>보물지도</title>
    <link rel="stylesheet" href="index.css">

</head>

<body>

<div class="map">
    <h1 id = "hint">SW마에스트로</h1>
</div>

</body>

</html>

CSS

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
* {
    margin: 0;
    padding: 0;
}

html, body{
    width: 100%;
    height: 100%;
}

.map{
    background:#0000ff;
    display:table;
    width: 100%;
    height: 100%;

}

#hint{
    color:#0000ff;
    display:table-cell;
    vertical-align:middle;
    text-align:center;
    line-height: 50%;

}

@media screen  and (min-width:100px) and (max-width: 720px) {
    /* CSS that should be displayed if width is equal to or less than 800px goes here */

    .map{
        background:#00ff00;
        transition-property: background;
        transition-duration: 0.5s;
    }

    #hint{
        color:#00ff00;
        transition-property:color;
        transition-duration: 0.5s;
    }

    .map:hover {
        background:#ff0000;
    }

    #hint:hover{
        color:#ffffff;
    }
}

Reference

Success Notice:
수고하셨습니다. :+1:

Leave a comment