<hr> 구분선 스타일 가이드
HTML <hr> 태그를 원하는 색상이나 두께 등 원하는 디자인으로 스타일하는 방법에 대해 알아보겠습니다.
CSS를 적용하면 <hr> 로 나타내는구분선을 나만의 스타일이 적용된 모습으로 디자인할 수 있습니다.
브라우저에서 제공하는 기본 스타일
디자인 관점에서 보면 대부분의 모던 웹사이트는 기본 스타일을 그대로 사용하지 않고 재정의하는 경우가 많습니다. 브라우저에서 제공하는 기본 스타일이 웹사이트의 디자인 요구 사항과 맞지 않는 경우가 많기 때문입니다.
<hr>
커스텀 스타일링 하기
가장 많이 사용하는 다양한 스타일 가이드를 참고해 보세요.
실선 패턴
가장 직관적이고 널리 쓰이는 방식은 border: none을 지정하고, height로 구분선 두께를 조절하고 background로 색상을 채우는 방식입니다. 너비는 width로 조절할 수 있습니다.
<hr class="solid-hr">
hr.solid-hr {
border: none; /* 기본 3D 입체 테두리 제거 */
height: 2px; /* 선의 두께 */
background: gray; /* 선의 색상 */
width: 50%; /* 선의 가로 길이 (생략 시 100%): 자동 가운데 정렬함 */
}
활용 예제 1
<hr class="solid-hr">
hr.solid-hr {
border: none;
height: 5px;
background: orangered;
width: 50%;
}
활용 예제 2
<hr class="solid-hr">
hr.solid-hr {
border: none;
height: 5px;
background: linear-gradient(to right, orange, red);
}
점선 및 대시선 패턴
이 경우 테두리가 중복되지 않도록 한쪽 면인 border-top 속성만 살려서 점선(dotted)이나 대시선(dashed)을 만들 수 있습니다. 이 방식을 쓸 때는 height를 주지 않습니다.
점선 패턴
<hr class="dotted-hr">
hr.dotted-hr {
border: none; /* 기본 3D 입체 테두리 제거 */
border-top-style: dotted;
border-top-width: 2px; /* 선의 두께 */
border-top-color: gray; /* 선의 색상 */
width: 50%; /* 선의 가로 길이 (생략 시 100%): 자동 가운데 정렬함 */
}
활용 예제 1
<hr class="dotted-hr">
hr.dotted-hr {
border: none;
border-top-style: dotted;
border-top-width: 5px;
border-top-color: orangered;
width: 50%;
}
활용 예제 2
<hr class="dotted-hr">
hr.dotted-hr {
border: none;
border-top-style: dotted;
border-top-width: 5px;
border-top-color: orangered;
}
대시선 패턴
<hr class="dashed-hr">
hr.dashed-hr {
border: none; /* 기본 3D 입체 테두리 제거 */
border-top-style: dashed;
border-top-width: 2px; /* 선의 두께 */
border-top-color: gray; /* 선의 색상 */
width: 50%; /* 선의 가로 길이 (생략 시 100%): 자동 가운데 정렬함 */
}
활용 예제 1
<hr class="dashed-hr">
hr.dashed-hr {
border: none;
border-top-style: dashed;
border-top-width: 5px;
border-top-color: orangered;
width: 50%;
}
활용 예제 2
<hr class="dashed-hr">
hr.dashed-hr {
border: none;
border-top-style: dashed;
border-top-width: 5px;
border-top-color: orangered;
}
대칭 구분선(Symmetrical Divider)
<hr class="symmetrical-hr">
hr.symmetrical-hr {
position: relative;
overflow: visible;
border: none;
width: 300px; /* 가운데 굵은 선 너비 */
max-width: calc(33.333% - 10px); /* 가운데 굵은 선 너비와 상관없이 반응형 웹으로 구현됨 */
height: 10px; /* 가운데 굵은 선 두께 */
background: gray; /* 가운데 굵은 선 색상 */
}
hr.symmetrical-hr:before,
hr.symmetrical-hr:after {
content: "";
position: absolute;
top: 50%;
width: 100%;
height: 1px; /* 양쪽 가는 선 두께 */
background: gray; /* 양쪽 가는 선 색상 */
}
hr.symmetrical-hr:before {
transform: translateX(calc(-100% - 5px)) translateY(-50%);
}
hr.symmetrical-hr:after {
transform: translateX(calc(100% + 5px)) translateY(-50%);
}
활용 예제 1
<hr class="symmetrical-hr">
hr.symmetrical-hr {
position: relative;
overflow: visible;
border: none;
width: 300px;
max-width: calc(33.333% - 10px);
height: 8px;
background: orangered;
}
hr.symmetrical-hr:before,
hr.symmetrical-hr:after {
content: "";
position: absolute;
top: 50%;
width: 100%;
height: 1px;
background: orangered;
}
hr.symmetrical-hr:before {
transform: translateX(calc(-100% - 5px)) translateY(-50%);
}
hr.symmetrical-hr:after {
transform: translateX(calc(100% + 5px)) translateY(-50%);
}
활용 예제 2
<hr class="symmetrical-hr">
hr.symmetrical-hr {
position: relative;
overflow: visible;
border: none;
width: 300px;
max-width: calc(33.333% - 10px);
height: 10px;
background: linear-gradient(to right, orange, red);
border-radius: 5px;
}
hr.symmetrical-hr:before,
hr.symmetrical-hr:after {
content: "";
position: absolute;
top: 50%;
width: 100%;
height: 1px;
background: orangered;
}
hr.symmetrical-hr:before {
transform: translateX(calc(-100% - 5px)) translateY(-50%);
}
hr.symmetrical-hr:after {
transform: translateX(calc(100% + 5px)) translateY(-50%);
}