You are here: Reference > JavaScript > client-side > style handling > properties > captionSide

captionSide style property

Browser support:
8
Specifies or returns the position of the caption box within a table element.
Note: The captionSide property is supported in Internet Explorer from version 8.
Earlier versions of Internet Explorer support the align property to provide similar functionality, but that property is deprecated in HTML 4.01. If you want to align a caption element to the top or bottom side of a table element, use the vAlign property in Internet Explorer earlier than version 8.

Syntax:

object.captionSide;
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: caption-side

Possible values:

The type of this property is string.
 One of the following values: 
bottom
Positions the caption box below the table box.
inherit
Takes the value of this property from the computed style of the parent element.
left
Positions the caption box to the left of the table box.
right
Positions the caption box to the right of the table box.
top
Positions the caption box above the table box.
Default: top.

Example HTML code 1:

This example illustrates the use of the caption-side property:
<head>
    <style>
        .example {
            caption-side: bottom; 
            width: auto;
            text-align: center;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <table>
        <caption valign="bottom" class="example">Fruits</caption>
        <tr>
            <td>Apple</td>
            <td>13.46</td>
        </tr>
        <tr>
            <td>Pear</td>
            <td>35.21</td>
        </tr>
        <tr>
            <td>Peach</td>
            <td>23.12</td>
        </tr>
    </table>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the captionSide property in JavaScript:
<head>
    <script type="text/javascript">
        function ChangeCaptionSide (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 caption = document.getElementById ("myCap");

            if ('captionSide' in caption.style) {
                caption.style.captionSide = selectState;
            } else {
                // Internet Explorer before version 8
                caption.align = selectState;
            }
        }
    </script>
</head>
<body>
    <table>
        <caption id="myCap">Fruits</caption>
        <tr>
            <td>Apple</td>
            <td>13.46</td>
        </tr>
        <tr>
            <td>Pear</td>
            <td>35.21</td>
        </tr>
        <tr>
            <td>Peach</td>
            <td>23.12</td>
        </tr>
    </table>

    <select onchange="ChangeCaptionSide (this);" size="4">
        <option selected="selected" />bottom
        <option />left
        <option />right
        <option />top
    </select>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content