<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 10px;
width: 150px;
box-sizing: border-box;
}
#small {
border: 10px solid black;
}
#large {
border: 30px solid black;
}
</style>
</head>
<body>
<div id="small">Hello</div>
<div id="large">Hello</div>
</body>
</html>
위의 코드를 웹페이지로 나타내면 #small과 #large의 크기는 다르게 보인다.
- content를 기준으로 너비가 150px가 적용되었기 때문.
두 요소의 크기를 같게 하려면 box-sizing이라는 속성을 이용하면 된다.
- box-sizing의 기본값은 content-box (content의 크기만큼 width와 height 값이 지정되는 것)이므로 값을 border-box로 변경하면 된다.
- 대부분 border-box를 사용한다.
'html & css > 개념' 카테고리의 다른 글
포지션 (position) (1) | 2023.11.22 |
---|---|
마진 겹침 (margin-collapsing) (0) | 2023.11.22 |
박스모델 (1) | 2023.11.21 |
인라인 VS 블럭레벨 (2) | 2023.11.21 |
서체 다루기 (0) | 2023.11.20 |