스타일 backgroundColor 속성
예시
문서의 배경색 설정:
document.body.style.backgroundColor = "red";
아래에서 더 많은 "직접 사용해 보기" 예를 살펴보세요.
정의 및 사용
backgroundColor 속성은 요소의 배경색을 설정하거나 반환합니다.
브라우저 지원
표의 숫자는 속성을 완전히 지원하는 첫 번째 브라우저 버전을 지정합니다.
Property | |||||
---|---|---|---|---|---|
backgroundColor | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
통사론
backgroundColor 속성을 반환합니다.
object.style.backgroundColor
backgroundColor 속성을 설정합니다.
object.style.backgroundColor = "color|transparent|initial|inherit"
속성 값
Value | Description |
---|---|
color | Specifies the background color. Look at CSS Color Values for a complete list of possible color values |
transparent | Default. The background color is transparent (underlying content will shine through) |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
기술적 세부 사항
기본값: | 투명한 |
---|---|
반환 값: | 배경색을 나타내는 String |
CSS 버전 | CSS1 |
더 많은 예
예시
특정 <div> 요소의 배경색 설정:
document.getElementById("myDiv").style.backgroundColor = "lightblue";
예시
특정 <div> 요소의 배경색을 반환합니다.
alert(document.getElementById("myDiv").style.backgroundColor);
예시
문서의 배경색 반환:
alert(document.body.style.backgroundColor);
관련 페이지
CSS 튜토리얼: CSS 배경
CSS 참조: background-color 속성
HTML DOM 참조: 배경 속성