div태그 좌우 반으로 나누기



html)

float 속성으로 좌우로 배치하고 box-sizing: border-box 속성으로 너비가 테두리영역까지 포함되도록 한다

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
<!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>
    div {
        width: 100%;
        height: 300px;
        
        border: 1px solid #000;
    }
    div.left {
        width: 50%;
        float: left;
        box-sizing: border-box;
        
        background: #ff0;
    }
    div.right {
        width: 50%;
        float: right;
        box-sizing: border-box;
        
        background: #0ff;
    }
    </style>
</head>
 
<body>
    <div>
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>
</html>
cs



결과

+ Recent posts