Chrome,Safari忽略表格中的最大宽度 [英] Chrome, Safari ignoring max-width in table
问题描述
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = windows-1251/>
< title>< / title>
< / head>
< body>
< table style =width:100%;>
< tr>
< td>
< table style =width:100%; max-width:1000px; background:#000099;>
< tr>
< td>
001
< / td>
< / tr>
< / table>
< / td>
< / tr>
< / table>
< / body>
< / html>
问题是Chrome和Safari忽略max-width:1000px
我的朋友发现我们可以通过为内部表添加display:block
来阻止它,并且它可以以某种方式工作。
所以,我想知道的是 - 有没有其他方法可以解决这个问题,为什么会发生这种情况?
最大宽度适用于块元素。 < table>
既不是 block 和内嵌。含糊不清?哈哈。您可以使用 display:block; max-width:1000px
并忘记 width:100%
。 Chrome和Safari遵循规则!
2017年5月编辑:请注意,此评论是7年前制作的(2010年!)。我怀疑浏览器多年来改变了一堆(我不知道,我不再做网页设计)。我建议使用更新的解决方案。
I've got HTML code like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title></title>
</head>
<body>
<table style="width:100%;">
<tr>
<td>
<table style="width:100%; max-width:1000px; background:#000099;">
<tr>
<td>
001
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
The problem is that Chrome and Safari are ignoring "max-width:1000px"
My friend has found that we can prevent it by adding "display:block"
for the inner table, and it's somehow working.
So, what I want to know is - are there any other ways of solving this problem and why is this happening?
Max-width applies to block elements. <table>
is neither block nor inline. Ambiguous enough? haha. You can use display:block; max-width:1000px
and forget about width:100%
. Chrome and Safari follow the rules!
Edit May 2017: please note, this comment was made 7 years ago (in 2010!). I suspect browsers have changed a bunch over the years (I wouldn't know, I no longer do web design). I recommend using a more recent solution.
这篇关于Chrome,Safari忽略表格中的最大宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!