共用方式為


visibility

設定是否顯示物件內容。

語法

{ visibility: sVisibility }

可能的值

sVisibility

指定下列其中一個值的字串:

inherit

預設值。物件會繼承下一個父物件的可見性。

hidden

隱藏物件。

visible

物件為可見。

此屬性的預設值為 inherit 。此階層式樣式表屬性不是繼承屬性。

備註

display 屬性設為 none 的物件不同的是,使用 visibility 屬性而隱藏的物件仍然在內容版面配置中保留與它們可見時相同的實體空間。您可以透過指令碼來變更可見性,根據使用者互動來顯示和隱藏重疊的內容。

範例

下列範例使用 visibility 屬性來決定是否看得到物件。此範例會呼叫內嵌 (全域) 樣式表兩次來隱藏影像,然後在使用者將指標移到文字上並離開文字時顯示影像:

<style>
    .vis1 {visibility:visible}
    .vis2 {visibility:hidden}
</style>
</head>
<body>
<img id="oSphere" src="sphere.jpg">
<p onmouseover="oSphere.className='vis2'" 
   onmouseout="oSphere.className='vis1'">
   Move the mouse over this text to make the sphere   
   disappear.</p>

標準資訊

您可以在 Cascading Style Sheets (CSS), Level 2 (CSS2) (階層式樣式表 (CSS) 層級 2 (CSS2)) Ee371214.xtlink_newWindow(zh-tw,Expression.40).png 找到此屬性的定義。

適用範圍

a, address, applet, b, big, blockquote, body, button, caption, center, cite, code, col, colgroup, custom, dd, defaults, dfn, div, dl, dt, em, embed, fieldset, form, hn, hr, html, i, iframe, img, input type=button, input type=checkbox, input type=file, input type=image, input type=password, input type=radio, input type=reset, input type=submit, input type=text, li, object, ol, p, s, select, span, sub, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var, xmp

另請參閱

概念

display