gpt4 book ai didi

html - 设置表格的最大宽度

转载 作者:搜寻专家 更新时间:2023-10-31 22:39:36 25 4
gpt4 key购买 nike

我正在尝试设置表格的最大宽度,但它似乎不起作用。如果表格中的单词太长,它会自动扩展表格的宽度。我该如何阻止这种情况发生,而是让太长的词转到下一行?

<style>table {
max-width: 300px;
}

table,
td {
border: 1px solid red;
}

div {
border: 1px solid blue;
word-wrap: break-word;
}

</style>
<table>

<tr>
<td>
<div> hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
</div>
</td>
</tr>

</table>

最佳答案

如果你想让你的 max-width 起作用,你需要在表格上设置 CSS 属性 table-layout: fixed; 并使用 width,而不是最大宽度

https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout

关于html - 设置表格的最大宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40063418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com