📄 tables.html
字号:
</ol><p>This gives a maximum and minimum width for each column. Column widths influence the final table width as follows:</p> <ol><li>If the 'table' or 'inline-table' element's <a href="visudet.html#propdef-width" class="noxref"><spanclass="propinst-width">'width'</span></a> property has a specified value (W)other than 'auto', the property's computed value is the greater of Wand the minimum width required by all the columns plus cellspacing or borders (MIN). If W is greater than MIN, the extra width should bedistributed over the columns.<li>If the 'table' or 'inline-table' element has 'width: auto', thecomputed table width is the greater of the table's containing blockwidth and MIN. However, if the maximum width required by the columnsplus cell spacing or borders (MAX) is less than that of the containing block, use MAX.</ol><p>A percentage value for a column width is relative to the tablewidth. If the table has 'width: auto', a percentage represents aconstraint on the column's width, which a UA should try tosatisfy. (Obviously, this is not always possible: if the column'swidth is '110%', the constraint cannot be satisfied.)</p><div class="note"><P> <em><strong>Note.</strong> In this algorithm, rows (and rowgroups) and columns (and column groups) both constrain and areconstrained by the dimensions of the cells they contain. Setting thewidth of a column may indirectly influence the height of a row, andvice versa.</em></div><h3>17.5.3 <a name="height-layout">Table height algorithms</a></h3><P>The height of a table is given by the <a href="visudet.html#propdef-height" class="noxref"><spanclass="propinst-height">'height'</span></a> property for the 'table' or'inline-table' element. A value of 'auto' means that the height is thesum of the row heights plus any cell spacing or borders. Any othervalue specifies the height explicitly; the table may thus be taller orshorter than the height of its rows. CSS2 does not specify renderingwhen the specified table height differs from the content height, inparticular whether content height should override specified height; ifit doesn't, how extra space should be distributed among rows that addup to less than the specified table height; or, if the content heightexceeds the specified table height, whether the UA should provide ascrolling mechanism. <strong>Note.</strong> Future versions of CSSmay specify this further.<P>The height of a 'table-row' element's box is calculated once theuser agent has all the cells in the row available: it is the maximumof the row's specified <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a>and the minimum height (MIN) required by the cells. A <a href="visudet.html#propdef-height" class="noxref"><spanclass="propinst-height">'height'</span></a> value of 'auto' for a'table-row' means the computed row height is MIN. MIN depends on cellbox heights and cell box alignment (much like the calculation of a <ahref="visudet.html#line-height">line box</a> height). CSS2 does notdefine what percentage values of <a href="visudet.html#propdef-height" class="noxref"><spanclass="propinst-height">'height'</span></a> refer to when specified fortable rows and row groups.<P>In CSS2, the height of a cell box is the maximum of the tablecell's <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a> property and theminimum height required by the content (MIN). A value of 'auto' for<a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a> implies a computed valueof MIN. CSS2 does not define what percentage values of <a href="visudet.html#propdef-height" class="noxref"><spanclass="propinst-height">'height'</span></a> refer to when specified fortable cells.<P>CSS2 does not specify how cells that span more than rowaffect row height calculations except that the sum of the rowheights involved must be great enough to encompass the cellspanning the rows.<P>The <a href="visudet.html#propdef-vertical-align" class="noxref"><span class="propinst-vertical-align">'vertical-align'</span></a>property of each table cell determines its alignment within the row.Each cell's content has a baseline, a top, a middle, and a bottom, asdoes the row itself. In the context of tables, values for <a href="visudet.html#propdef-vertical-align" class="noxref"><spanclass="propinst-vertical-align">'vertical-align'</span></a> have thefollowing meanings:</p><dl><dt><strong>baseline</strong></dt><dd>The baseline of the cell is put at the same height as the baselineof the first of the rows it spans (see below for the definition ofbaselines of cells and rows).<dt><strong>top</strong></dt><dd>The top of the cell box is aligned with the top of the first rowit spans.<dt><strong>bottom</strong></dt><dd>The bottom of the cell box is aligned with the bottom of the lastrow it spans.<dt><strong>middle</strong></dt><dd>The center of the cell is aligned with the center of the rows itspans.<dt><strong>sub, super, text-top, text-bottom</strong></dt><dd>These values do not apply to cells; the cell is aligned at thebaseline instead.</dl><p>The baseline of a cell is the baseline of the first <a href="visuren.html#line-box">line box</a> inthe cell. If there is no text, the baseline is the baseline ofwhatever object is displayed in the cell, or, if it has none, thebottom of the cell box. The maximum distance between the top of thecell box and the baseline over all cells that have'vertical-align: baseline' is used to set the baseline of the row. Hereis an example:</p><div class="figure"><p><img src="images/cell-align.gif" alt="Example of verticallyaligning the cells"><SPAN class="dlink"> <A name="img-cell-align" href="images/longdesc/cell-align-desc.html" title="Long description of example illustrating table row heightcalculations and vertical cell alignment">[D]</A></SPAN><p class="caption"> Diagram showing the effect ofvarious values of 'vertical-align' on table cells.</div><p>Cell boxes 1 and 2 are aligned at their baselines. Cell box 2 hasthe largest height above the baseline, so that determines the baselineof the row. Note that if there is no cell box aligned at itsbaseline, the row will not have (nor need) a baseline.</p><p>To avoid ambiguous situations, the alignment of cells proceeds inthe following order:</p><ol><li>First the cells that are aligned on their baseline arepositioned. This will establish the baseline of the row. Next thecells with 'vertical-align: top' are positioned.<li>The row now has a top, possibly a baseline, and a provisionalheight, which is the distance from the top to the lowest bottom of thecells positioned so far. (See conditions on the cell paddingbelow.)<li>If any of the remaining cells, those aligned at the bottom or themiddle, have a height that is larger than the current height of therow, the height of the row will be increased to the maximum of thosecells, by lowering the bottom.<li>Finally the remaining cells are positioned.</ol><P>Cell boxes that are smaller than the height of the row receiveextra top or bottom padding.</p><h3>17.5.4 <a name="column-alignment">Horizontal alignment in a column</a></h3><p>The horizontal alignment of a cell's content within a cell box isspecified with the <a href="text.html#propdef-text-align" class="noxref"><spanclass="propinst-text-align">'text-align'</span></a> property.<P>When the <a href="text.html#propdef-text-align" class="noxref"><span class="propinst-text-align">'text-align'</span></a>property for more than one cell in a column is set to a <spanclass="index-inst" title="<string>"><a name="x17" href="syndata.html#value-def-string" class="noxref"><spanclass="value-inst-string"><string></span></a></span> value, thecontent of those cells is aligned along a vertical axis. The beginningof the string touches this axis. Character directionality determineswhether the string lies to the left or right of the axis.<p>Aligning text in this way is only useful if the text fits on oneline. The result is undefined if the cell content spans more than oneline.<p>If value of <a href="text.html#propdef-text-align" class="noxref"><span class="propinst-text-align">'text-align'</span></a>for a table cell is a string but the string doesn't occur in the cellcontent, the end of the cell's content touches the vertical axis ofalignment.<p>Note that the strings do not have to be the same for each cell,although they usually are.<P>CSS does not provide a way specify the offset of the verticalalignment axis with respect to the edge of a column box.<div class="example"><P style="display:none">Example(s):</P><P>The following style sheet:</p><PRE> TD { text-align: "." } TD:before { content: "$" }</PRE><P>will cause the column of dollar figuresin the following HTML table:</p><PRE class="html-example"> <TABLE> <COL width="40"> <TR> <TH>Long distance calls <TR> <TD> 1.30 <TR> <TD> 2.50 <TR> <TD> 10.80 <TR> <TD> 111.01 <TR> <TD> 85. <TR> <TD> 90 <TR> <TD> .05 <TR> <TD> .06 </TABLE></PRE><P>to align along the decimal point. For fun,we have used the <a name="x18"><span class="index-inst" title=":before">:before</span></a>pseudo-element to insert a dollar sign before each figure. The tablemight be rendered as follows:</P><PRE>Long distance calls $1.30 $2.50 $10.80 $111.01 $85. $90 $.05 $.06</PRE></div><h3>17.5.5 <a name="dynamic-effects">Dynamic row and column effects</a></h3><p>The <a href="visufx.html#propdef-visibility" class="noxref"><span class="propinst-visibility">'visibility'</span></a> propertytakes the value 'collapse' for row, row group, column, and columngroup elements. This value causes the entire row or column to beremoved from the display, and the space normally taken up by the rowor column to be made available for other content. The suppression ofthe row or column, however, does not otherwise affect the layout ofthe table. This allows dynamic effects to remove table rows or columnswithout forcing a re-layout of the table in order to account for thepotential change in column constraints.<h2>17.6 <a name="borders">Borders</a></h2><p>There are two distinct models for setting borders on table cells inCSS. One is most suitable for so-called <a name="x19"><span class="index-inst"title="separated borders">separated borders</span></a> around individual cells, theother is suitable for borders that are continuous from one end of thetable to the other. Many border styles can be achieved with eithermodel, so it is often a matter of taste which one is used.<div class="propdef"><dl><dt><span class="index-def" title="'border-collapse'"><a name="propdef-border-collapse" class="propdef-title"><strong>'border-collapse'</strong></a></span><dd><table class="propinfo" cellspacing=0 cellpadding=0><tr valign=baseline><td><em>Value:</em> <td>collapse | separate | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a><tr valign=baseline><td><em>Initial:</em> <td>collapse<tr valign=baseline><td><em>Applies to:</em> <td>'table' and 'inline-table' elements<tr valign=baseline><td><em>Inherited:</em> <td>yes<tr valign=baseline><td><em>Percentages:</em> <td>N/A<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a></table></dl></div><P>This property selects a table's border model. The value 'separate'selects the separated borders border model. The value 'collapse'selects the collapsing borders model. The models are described below.<h3>17.6.1 <a name="separated-borders">The separated borders model</a></h3><div class="propdef"><dl><dt><span class="index-def" title="'border-spacing'"><a name="propdef-border-spacing" class="propdef-title"><strong>'border-spacing'</strong></a></span><dd><table class="propinfo" cellspacing=0 cellpadding=0><tr valign=baseline><td><em>Value:</em> <td><a href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length"><length></span></a> <a href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length"><length></span></a>? | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a><tr valign=baseline><td><em>Initial:</em> <td>0<tr valign=baseline><td><em>Applies to:</em> <td>'table'and 'inline-table' elements<tr valign=baseline><td><em>Inherited:</em> <td>yes<tr valign=baseline><td><em>Percentages:</em> <td>N/A<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a></table></dl></div><P>The lengths specify the distance that separates adjacent cellborders. If one length is specified, it gives both the horizontal andvertical spacing. If two are specified, the first gives the horizontalspacing and the second the vertical spacing. Lengths may not benegative.<p>In this model, each cell has an individual border. The<a href="tables.html#propdef-border-spacing" class="noxref"><span class="propinst-border-spacing">'border-spacing'</span></a> propertyspecifies the distance between the borders of adjacent cells. Thisspace is filled with the background of the table element. Rows,columns, row groups, and column groups cannot have borders (i.e., useragents must <span class="index-inst" title="ignore"><a name="x22"href="syndata.html#ignore">ignore</a></span> the border properties forthose elements).<div class="example"><P style="display:none">Example(s):</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -