display style property
Specifies or returns the element's display type.
With this property, you can set how the element should be rendered. The elements in HTML are mostly 'inline' or 'block' elements.
- An inline element should have floating content on its left and right side, too, but a block element fills the entire line, and nothing can be displayed at its left or right side.
- If an element is a block element, its display type can be changed with the float property, too.
The display property is also very useful in dynamic pages, because it allows the author to show or hide an element.
It is similar to the visibility property, but if you set the display property to 'none', it hides the entire element.
The 'hidden' value for the visibility property means that the contents of the element will be invisible, but the element
stays in its original position and size.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: display |
Possible values:
The type of this property is string.
One of the following values:
Object is rendered as a box. | |||||||
Same rendering rules for the child elements as the XUL bulletinboard element. | |||||||
Creates either block or inline boxes, depending on context. | |||||||
Object is rendered as a deck. | |||||||
Object is rendered as a grid. | |||||||
Object is rendered as a grid group. | |||||||
Object is rendered as a grid line. | |||||||
Object is rendered as a groupbox. | |||||||
Deprecated. Use inline-block value instead. Object is rendered as a block box inside an inline box. | |||||||
Object is rendered as a box inside an inline box. | |||||||
Object is rendered as a grid inside an inline box. | |||||||
Object is rendered as a stack inside an inline box. | |||||||
Deprecated. Use inline-table value instead. Object is rendered as a table inside an inline box. | |||||||
Declares content generated before or after a box to be a marker. | |||||||
Object is rendered as a popup. | |||||||
Creates either block or inline boxes, depending on context. | |||||||
Object is rendered as a stack. | |||||||
Object is rendered as a box. | |||||||
Object is rendered as a box inside an inline box. | |||||||
Element is rendered as a block. You are able to change a block element's floating rules with the styleFloat property. | |||||||
Creates either block or inline boxes, depending on context. | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
Default. Element is rendered as an inline box. | |||||||
Object is rendered as a block box inside an inline box. | |||||||
Object is rendered as a table inside an inline box. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the li element. | |||||||
Declares content generated before or after a box to be a marker. | |||||||
Object is not rendered. | |||||||
Equivalent of the default styling of the ruby element. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the ruby base text element. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the ruby base container element. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the ruby text element. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the ruby text container element. Supported in Internet Explorer from version 8. | |||||||
Creates either block or inline boxes, depending on context. Supported in Internet Explorer from version 8. | |||||||
Specifies a block-level table. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the caption element. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the td or th element. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the col element. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the colgroup element. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the tfoot element. | |||||||
Equivalent of the default styling of the thead element. | |||||||
Equivalent of the default styling of the tr element. Supported in Internet Explorer from version 8. | |||||||
Equivalent of the default styling of the tbody element. Supported in Internet Explorer from version 8. |
Default: inline.
Example HTML code 1:
This example illustrates the use of the display property:
|
||||
<head> <style> .block { display: block; background-color: #CFCFCF; } </style> </head> <body> <p>This is a <b id="aTag" class="block">block</b> and this is an <b>inline</b> element. </p> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the display property in JavaScript:
|
||||
<head> <script type="text/javascript"> function ChangeDisplay (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the text of the selected option var selectState = selectTag.options[whichSelected].text; var anchor = document.getElementById ("aTag"); anchor.style.display = selectState; } </script> </head> <body> <p>Change the display type<a id="aTag" style="background-color: #CFCFCF;">of this element</a> with the list box!</p> <select onchange="ChangeDisplay (this);" size="7"> <option />block <option />none <option selected="selected" />inline <option />inline-block <option />list-item <option />table-header-group <option />table-footer-group </select> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, applet, b, bdo, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, marquee, menu, nobr, object, ol, optgroup, option, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
External links:
User Contributed Comments