修改HTML表格的单元格
我有一个使用CSS设计的HTML表格。该表由两行组成,但上行只需要3列,而下行有5列修改HTML表格的单元格,html,css,html-table,Html,Css,Html Table,我有一个使用CSS设计的HTML表格。该表由两行组成,但上行只需要3列,而下行有5列 <table class="xp-flt-leg-sum" name="flightLegSummary"> <tbody> <!--Row 1--> <tr class="xp-flt-ctyttl-fnt" name="from2City"> <!--Col1 -->
<table class="xp-flt-leg-sum" name="flightLegSummary">
<tbody>
<!--Row 1-->
<tr class="xp-flt-ctyttl-fnt" name="from2City">
<!--Col1 -->
<td colspan="2" class="flightLegSummary xp-fl-md-lg"><span id="departureCity0">Seattle</span></td>
<!--Col2 -->
<td colspan="1" class="xp-fl-md-lg"><span id="arrivalCity0">New York</span></td>
<!--Col3 -->
<td colspan="2">
<span id="connectingCity-0-0" class="xp-connecting-cities">
Charlotte
</span>
</td>
</tr>
<tr class="xp-flt-arptttl-fnt">
<!--Col1 -->
<td class="xp-flt-mdl-leg-col1 ">
<span id="departureAirport0">SEA </span>
<span id="departureTime0">
10:15pm
</span>
</td>
<!--Col2 -->
<td class="xp-flt-mdl-leg-colicn ">
<span class="xp-flt-mdl-drctn-icn" id="directionIcon0"><!-- --></span>
</td>
<!--Col3 -->
<td class="xp-flt-mdl-leg-col2 ">
<span id="arrivalAirport0">LGA </span>
<span id="arrivalTime0">
9:45am
</span>
<span style="display:inline-block;" id="addedDays">
+1 Tag
</span>
</td>
<!--Col4 -->
<td class="xp-flt-mdl-leg-col3">
<span class="xp-flt-leg-stop-span" id="flight0StopCount">
1 Stopp
</span>
</td>
<!--Col5 -->
<td class="xp-flt-mdl-leg-col4">
<span id="flightDuration0">8Std.​30Min.</span>
</td>
</tr>
</tbody>
</table>
我面临的问题是,我想将以下所有单元格修改为某个宽度:
<Row1,Col1> 98px wide
<Row1,Col2> 130px wide
<Row2,Col1> 86px wide
<Row2,Col2> 12px wide
<Row2,Col3> 130px wide
<Row2,Col4> 76px wide
我一直在努力,似乎无法将行修改为所需的宽度。另外,我不明白colspan在第一行中的作用。然而,当我将其移除时,它确实会破坏细胞的定位 Colspan设置单元格应跨越的列数。这里有3个标题单元格,第一个标题单元格下面有2列,第二个标题单元格下面有1列,第三个标题单元格下面有5列 看起来你想要3个单元格在上面,4列在下面,对吗?如果是这样,您需要将第三个标题单元格设置为colspan=1,它的宽度为76px,如下面的列所示
希望这有帮助 将border=1添加到表标记可能有助于您理解colspan的功能。这将向您展示如何将第1行的第1列展开,以覆盖其下该行的两列。有时,可视化显示它的工作方式比一堆基于文本的解释要好。我认为Michelle很好地澄清了您的表格问题,我想补充一点,基于您的两行静态布局和不同的单元格宽度,您是否考虑过在一个容器中使用两行简单的浮动div?我想您会有更大的灵活性和更简单的代码。您想要这样的东西吗@Kyle Undefined:这是我想要的,但在我的情况下,这样做似乎不起作用。你有没有可能使用DIV的?
<Row1,Col1> 98px wide
<Row1,Col2> 130px wide
<Row2,Col1> 86px wide
<Row2,Col2> 12px wide
<Row2,Col3> 130px wide
<Row2,Col4> 76px wide