HTML DOM 스타일의 화면 표시 특성
정의 및 사용
속성 세트를 표시하거나 요소의 표시 형식을 반환합니다.
좌우 콘텐츠 플로팅되는 인라인 요소 : 주로 "인라인"또는 "블록"요소 HTML 요소. 블록 요소는 전체 라인을 작성하고 아무것도 왼쪽 또는 오른쪽에 표시 할 수 없습니다.
디스플레이 속성은 또한 저자 표시하거나 요소를 숨길 수 있습니다. 가시성 속성 유사합니다. 그러나 디스플레이 설정 한 경우 : 숨겨진 콘텐츠 요소가 표시되지 않습니다,하지만 요소는 원래의 위치 및 크기 유지 : 없음을, 당신은 가시성 설정 한 경우, 전체 요소를 숨 깁니다.
문법
디스플레이 등록 정보 설정 :
Object.style.display="value"
디스플레이 속성을 반환합니다 :
Object.style.display
值 | 描述 |
---|---|
block | 元素呈现为块级元素。 |
compact | 元素呈现为块级元素或内联元素,取决于上下文。 |
inherit | display 属性的值从父元素继承。 |
inline | 默认。元素呈现为内联元素。 |
inline-block | 元素呈现为内联盒子内的块盒子。 |
inline-table | 元素呈现为内联表格(类似 <table>),表格前后没有换行符。 |
list-item | 元素呈现为列表。 |
marker | 该值在盒子前后设置内容作为标记(与 :before 和 :after 伪元素一起使用,否则该值与 "inline" 是相同的)。 |
none | 元素不会被显示。 |
run-in | 元素呈现为块级或内联元素,取决于上下文。 |
table | 元素呈现为块级表格(类似 <table>),表格前后带有换行符。 |
table-caption | 元素呈现为表格标题(类似 <caption>)。 |
table-cell | 元素呈现为表格单元格(类似 <td> 和 <th>)。 |
table-column | 元素呈现为单元格的列(类似 <col>)。 |
table-column-group | 元素呈现为一个或多个列的分组(类似 <colgroup>)。 |
table-footer-group | 元素呈现为表格页脚行(类似 <tfoot>)。 |
table-header-group | 元素呈现为表格页眉行(类似 <thead>)。 |
table-row | 元素呈现为表格行(类似 <tr>)。 |
table-row-group | 元素呈现为一个或多个行的分组(类似 <tbody>)。 |
브라우저 지원
모든 주요 브라우저는 디스플레이 속성을 지원합니다.
참고 : IE7 및 이전 버전은 "상속"값을 지원하지 않습니다.IE8은 "상속"지원!의 DOCTYPE을 제공합니다. IE9 지원 "상속".
팁과주의 사항
팁 : 소자 블록 요소 경우, 그 표시 형태는 플로트 속성에 의해 변경 될 수있다.
예
예
버튼을 클릭하면 요소가 표시되지 않는 경우 :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function demoDisplay(){
document.getElementById("p1").style.display="none";
}
function demoVisibility(){
document.getElementById("p2").style.visibility="hidden";
}
</script>
</head>
<body>
<p id="p1">这是一些文本。</p>
<p id="p2">这是一些文本。</p>
<input type="button" onclick="demoDisplay()" value="隐藏显示属性的文本">
<input type="button" onclick="demoVisibility()" value="具有可见性属性的隐藏文本">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function demoDisplay(){
document.getElementById("p1").style.display="none";
}
function demoVisibility(){
document.getElementById("p2").style.visibility="hidden";
}
</script>
</head>
<body>
<p id="p1">这是一些文本。</p>
<p id="p2">这是一些文本。</p>
<input type="button" onclick="demoDisplay()" value="隐藏显示属性的文本">
<input type="button" onclick="demoVisibility()" value="具有可见性属性的隐藏文本">
</body>
</html>
»시도
스타일 개체