gpt4 book ai didi

css - @media 代码似乎在 Chrome 中不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 08:38:55 25 4
gpt4 key购买 nike

我有以下代码,当屏幕宽度小于特定数字时,我希望单元格折叠。

通常我习惯于使用 IE 遇到问题,但在这种情况下,IE 和 Firefox 都运行良好,Chrome 不会对我尝试做的事情使用react。

有什么想法吗?

我的代码是:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
@media screen and (max-width: 432px) {
.dynTd {display: block;}
}
</style>

</head>

<table style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, 'sans-serif';font-size:12px;">
<tr>
<td style="vertical-align: top">
<img src="https://xxxxxxxxxx/ccccccc.jpg" width="95" height="85">
</td>
<td style="vertical-align: top; display: block;">
<span style="color:#eb6909;font-size:14px;"><b>Name Surname</b></span><br>
<div style="font-size: 5px;">&nbsp;</div>
<span>Title</span>
<div style="font-size: 10px;">&nbsp;</div>
<span style="color:#eb6909;font-size:10px;">TEL</span> <span>+00 000000 000000</span><br>
<span style="color:#eb6909;font-size:10px;">MOBILE</span> <span>+00 000000 000000</span><br>
<span style="color:#eb6909;font-size:10px;">MAIL</span> <span>email@email.com</span><br>
<div style="font-size: 12px;">&nbsp;</div>
</td>
<td class="dynTd" style="width: 12px;"></td>
<td class="dynTd" style="vertical-align: top;">
<img src="https://xxxxxxxxxx/cccccccc.jpg" alt="Company Name" width="118" height="18">
<div style="font-size: 8px;">&nbsp;</div>
Company Name<br>
Company Address<br>
Zip code and City<br>
<div style="font-size: 5px;">&nbsp;</div>
<a href="http://www.company-url.de" style="color:#eb6909;text-decoration: none;"><b>www.company-url.de</b></a>
</td>
</tr>
</table>

</html>

最佳答案

根据 Tables 将 td 变成一个 block ,同时保留 tr 原样将导致浏览器进行补偿。规范,

If a child C of a 'table-row' box is not a 'table-cell', then generate an anonymous 'table-cell' box around C and all consecutive siblings of C that are not 'table-cell' boxes.

并且带有 display:block 的 td 元素不再是“table-cell”了!
因此,浏览器创建了这样一个匿名表格单元格。显然,Chrome 以不同于 FF 和 IE 的方式实现这一点。

解决方案是确保这种情况不会发生;例如,将表格中的所有元素转换为 block,这样就不需要匿名表格单元格了。

@media screen and (max-width: 432px) {
table, tr, td {display: block;}
}
<table style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, 'sans-serif';font-size:12px;">
<tr>
<td style="vertical-align: top">
<img src="https://xxxxxxxxxx/ccccccc.jpg" width="95" height="85">
</td>
<td style="vertical-align: top; display: block;">
<span style="color:#eb6909;font-size:14px;"><b>Name Surname</b></span><br>
<div style="font-size: 5px;">&nbsp;</div>
<span>Title</span>
<div style="font-size: 10px;">&nbsp;</div>
<span style="color:#eb6909;font-size:10px;">TEL</span> <span>+00 000000 000000</span><br>
<span style="color:#eb6909;font-size:10px;">MOBILE</span> <span>+00 000000 000000</span><br>
<span style="color:#eb6909;font-size:10px;">MAIL</span> <span>email@email.com</span><br>
<div style="font-size: 12px;">&nbsp;</div>
</td>
<td class="dynTd" style="width: 12px;"></td>
<td class="dynTd" style="vertical-align: top;">
<img src="https://xxxxxxxxxx/cccccccc.jpg" alt="Company Name" width="118" height="18">
<div style="font-size: 8px;">&nbsp;</div>
Company Name<br> Company Address<br> Zip code and City<br>
<div style="font-size: 5px;">&nbsp;</div>
<a href="http://www.company-url.de" style="color:#eb6909;text-decoration: none;"><b>www.company-url.de</b></a>
</td>
</tr>
</table>

这在所有浏览器中看起来都一样。您可以努力找到一种方法,使其再次看起来像您想要的样子...

关于css - @media 代码似乎在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44266091/

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