강의를 듣다가 강사님께서 border: none;
outline: none;
을 작성하시는 걸 보고 두 프로퍼티의 차이가 궁금해져서 찾아보았다.
작성한 마크업은 아래와 같다.
<div class="border-outline-container">
<div class="border"></div>
<div class="outline"></div>
</div>
작성한 css는 아래와 같다.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.border-outline-container {
margin: 1rem;
display: flex;
justify-content: space-between;
}
.border {
width: 150px;
height: 150px;
padding: 8px;
margin: 8px;
border: 2px solid green;
}
.outline {
width: 150px;
height: 150px;
padding: 8px;
margin: 8px;
outline: 2px solid red;
}
box-sizing: border-box;
를 작성했기 때문에 div의 너비와 높이는 border와 padding을 포함하게 된다. 따라서 content 자체는 150px에서 padding 양쪽을 합한 16px과 border 양쪽을 합한 4px을 뺀 130 * 130 의 크기를 갖는다.border-top
, border-left
등의 속성을 이용하여 특정 테두리만 스타일링 할 수 있다. outline은 outline-top
과 같은 속성이 없으므로 불가능하다.outline-offset
속성을 사용하여 offset을 작성할 수 있다. outline-offset: 15px;
을 작성했을 때 아래와 같이 offset이 적용되어 Box Model을 벗어나서 outline이 그려지게 된다.