• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>CSS3 Flexible Box Layout</title>
7
    <style>
8
        .flexbox {
9
            background-color: dimgray;
10
            width: 400px;
11
            height: 250px;
12
            margin: 10px 0;
13
            border-radius: 15px;
14
            display: -webkit-flex;
15
            display: flex;
16
            -webkit-flex-wrap: wrap;
17
            flex-wrap: wrap;
18
        }
19
        .item {
20
            background-color: darkgray;
21
            border-radius: 10px;
22
            width: 80px;
23
            height: 50px;
24
            margin: 10px;
25
            color: white;
26
            font-size: 26px;
27
            text-align: center;
28
            line-height: 50px;
29
        }
30
        #first .item:nth-child(1) { margin-right: auto; }
31
        #second .item:nth-child(2) { margin-right: auto; }
32
    </style>
33
</head>
34
​
35
<body>
36
​
37
    <h1>margin 속성을 이용한 플렉스 요소의 위치 설정</h1>
38
​
39
    <div class="flexbox" id="first">
40
        <div class="item">1</div>
41
        <div class="item">2</div>
42
        <div class="item">3</div>
43
    </div>
44
    <div class="flexbox" id="second">
45
        <div class="item">1</div>
46
        <div class="item">2</div>
47
        <div class="item">3</div>
48
    </div>
49
​
50
</body>
51
​
52
</html>