JavaScript에서 하나의 선언만으로 요소의 테두리 하단(border bottom) 속성을 모두 설정하려면 borderBottom 속성을 사용하면 됩니다. 이 속성을 활용하면 아래의 세 가지 값을 한꺼번에 지정할 수 있습니다.
- border-bottom-width : 테두리 아래쪽의 두께
- border-bottom-style : 테두리 아래쪽의 스타일(solid, dashed 등)
- border-bottom-color : 테두리 아래쪽의 색상
값은 일반적으로 "두께 스타일 색상" 순서로 공백을 두고 나열하여 작성합니다.
예제
아래 코드를 실행한 뒤 버튼을 클릭하면, 박스의 테두리 하단 속성이 thin dashed #000000으로 변경되는 것을 확인할 수 있습니다.
<!DOCTYPE html>
<html>
<head>
<style>
#box {
border: 2px dashed blue;
width: 120px;
height: 120px;
}
</style>
</head>
<body>
<button onclick="display()">Set border bottom color</button>
<div id="box">
<p>Demo Text</p>
<p>Demo Text</p>
</div>
<script>
function display() {
document.getElementById("box").style.borderBottom = "thin dashed #000000";
}
</script>
</body>
</html>