Css 固定html的宽度<;td>;标签
这是我的代码片段-Css 固定html的宽度<;td>;标签,css,html-table,fixed-width,Css,Html Table,Fixed Width,这是我的代码片段- <table style="border:1px solid #898989; table-layout:fixed"> <tr> <td width="25%" style="border:1px solid #898989; table-layout:fixed"> LongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongText </
<table style="border:1px solid #898989; table-layout:fixed">
<tr>
<td width="25%" style="border:1px solid #898989; table-layout:fixed">
LongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongText
</td>
<td width="75%" style="border:1px solid #898989; table-layout:fixed">
ShortText
</td>
</tr>
</table>
LongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtext
短文
我的输出是这样的-
内容不包含空格。我希望
的宽度在定义时保持不变(长文本为25%,短文本为75%)。我可以使用CSS属性吗?使用此属性
表格{
宽度:100%;/*与包含块的宽度相同*/
换行:打断单词;/*允许打断过长的单词*/
}
表格{
边框:1px实心#8989;
表布局:固定;
宽度:100%;
单词包装:打断单词;
}
运输署{
边框:1px实心#8989;
}
td:第一个孩子{
宽度:25%;
}
LongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtext
短文
使用此
表格{
宽度:100%;/*与包含块的宽度相同*/
换行:打断单词;/*允许打断过长的单词*/
}
表格{
边框:1px实心#8989;
表布局:固定;
宽度:100%;
单词包装:打断单词;
}
运输署{
边框:1px实心#8989;
}
td:第一个孩子{
宽度:25%;
}
LongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtext
短文
如果要使用CSS,只需在CSS中定义宽度即可
<td style="width=25%; overflow:hidden; border:1px solid #898989; table-layout:fixed">
选择overflow属性如果要使用CSS,只需在CSS中定义宽度即可
<td style="width=25%; overflow:hidden; border:1px solid #898989; table-layout:fixed">
选择overflow属性首先,您需要为表指定一个固定宽度,然后任何td将根据表的宽度获取宽度。我尝试了这个,请检查并让我知道是否为您工作:
<table style="border:1px solid #898989; table-layout:fixed;width:600px;">
<tr>
<td width="25%" style="border:1px solid #898989; table-layout:fixed;word-wrap:break-word">
LongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongText
</td>
<td width="75%" style="border:1px solid #898989; table-layout:fixed;word-wrap:break-word">
ShortText
</td>
</tr>
</table>
LongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtext
短文
表的宽度取决于您自己,因此,如果您希望表的宽度固定,请提供固定宽度,否则,如果您未提供任何宽度,则表的宽度将与其父div的宽度相同,例如:
<div style="width:600px">
<table style="border:1px solid #898989; table-layout:fixed;width:100%;">
<tr>
<td width="25%" style="border:1px solid #898989; table-layout:fixed;word-wrap:break-word">
LongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongText
</td>
<td width="75%" style="border:1px solid #898989; table-layout:fixed;word-wrap:break-word">
ShortText
</td>
</tr>
</table>
</div>
LongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtext
短文
在本例中,表的宽度为500px,因为表没有任何宽度,所以它的宽度与其父div的宽度相同。如果您要提供宽度,那么它将根据该宽度作为我的第一个注释。首先您需要给表指定一个固定的宽度,然后任何td将根据表的宽度获取宽度。我尝试了这个,请检查并让我知道是否为您工作:
<table style="border:1px solid #898989; table-layout:fixed;width:600px;">
<tr>
<td width="25%" style="border:1px solid #898989; table-layout:fixed;word-wrap:break-word">
LongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongText
</td>
<td width="75%" style="border:1px solid #898989; table-layout:fixed;word-wrap:break-word">
ShortText
</td>
</tr>
</table>
LongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtext
短文
表的宽度取决于您自己,因此,如果您希望表的宽度固定,请提供固定宽度,否则,如果您未提供任何宽度,则表的宽度将与其父div的宽度相同,例如:
<div style="width:600px">
<table style="border:1px solid #898989; table-layout:fixed;width:100%;">
<tr>
<td width="25%" style="border:1px solid #898989; table-layout:fixed;word-wrap:break-word">
LongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongText
</td>
<td width="75%" style="border:1px solid #898989; table-layout:fixed;word-wrap:break-word">
ShortText
</td>
</tr>
</table>
</div>
LongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtextLongtext
短文
在本例中,表的宽度为500px,因为表没有任何宽度,所以它的宽度与其父div的宽度相同。如果您要提供宽度,那么它将根据该宽度作为我的第一条评论。对于不适合宽度的文本,您到底希望如何处理?是否应该将其剪掉,流成多行?//将
宽度
添加到表中,以便表布局:固定
可以按预期工作。我已将
更新为宽度为99%
,但结果仍然相同。我已经在这里尝试过了-对于不适合宽度的文本,您到底希望发生什么情况-是否应该将其剪掉,流成多行,…?//将宽度
添加到表中,以便表布局:固定
可以按预期工作。我已将
更新为宽度为99%
,但结果仍然相同。我在这里尝试过-这是否意味着我也必须给
一个固定的宽度,而不是像我在问题中给出的%
年龄?嘿,我用你的这个问题更新了我以前的评论,所以请检查一下。在评论中,我们有一些文字限制,所以我用新的答案更新了我的评论。这是否意味着我也必须给
一个固定的宽度,而不是像我在问题中给出的%
年龄?嘿,我用你的这个问题更新了我以前的评论,所以请检查一下。在评论中,我们有一些文字限制,所以我用新的答案更新了我的评论。