内联样式被忽略
我的表格中有一个相当简单的单元格,具有内联样式:
<td style="text-align: right;"> Current Status: </td>
并且在 Firefox 和 Opera 中,text-align-right 都被忽略。我使用了 Firefox 的“firebug”,它显示了 。
知道会发生什么吗?我认为以这种方式指定的内联样式比任何链接样式表或继承样式具有最高优先级。
一如既往地感谢。
I have a fairly simple cell in a table with an inline style:
<td style="text-align: right;"> Current Status: </td>
And the text-align-right is being ignored, both in Firefox and Opera. I used Firefox's "firebug", and it shows me <td style="">
for this.
Any idea what could be going on? I thought that an inline style specified this way took highest priority over any linked style sheet or inherited style.
Thanks as always.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通常,当样式声明出现错误时,Firebug 会执行此操作。
Usually Firebug does that when there is an error with the style declaration.
有多种方法可以测试这里发生的情况。在 FireBug 中处理 CSS 类并启用和禁用样式,直到获得预期的结果。显然存在一些样式声明错误,导致该特定样式失败。因为您是对的,内联样式优先于外部样式表和父样式。既然您知道这一点,请重点关注 HTML 的表格区域,看看是否存在任何语法错误、覆盖该值的脚本等。
还要测试不同的文本样式这个“td”标签来查看其他样式是否有效,例如:
另请注意,如果方向属性为默认值“ltr”(从左到右),则
text-align:left
是默认值。因此,此 HTML 表格元素的某些样式可能没有被应用。There are numerous ways to test what is going on here. Work through your CSS's classes in FireBug and enable and disable styles until you get a result your expecting. There is obviously some style declaration error some where that is causing this particular style to fail. Because you are right, inline styles take priority over external style sheets, and over parent styles. Since you know this focus on the table area of your HTML and see if there are any syntax errors, scripts that are overriding the value, etc.
Also test different text styles for this "td" tag to see if other styles work, such as:
Also note that
text-align:left
is a default value if the direction property is "ltr" (left to right) which is default. So it could be possible that some of your styles for this HTML table element are not being applied.而不是您尝试添加一个
span
,它会遵守text-align
,而td
不会Instead of what you have try adding a
span
which will obey thetext-align
where thetd
will not(虽然 Firebug 不再存在,但它的功能已合并到 Firefox 中,而 Firefox 仍然可以表现出
style=""
行为。)请务必检查开发控制台,因为如果这是由以下原因引起的,则可能会列出错误内容安全策略 (CSP) 设置/限制。
CSP 设置可以通过 Web 服务器 HTTP 响应中的
Content-Security-Policy
标头指定,也可以使用(While Firebug no longer exists, it's capabilities were folded into Firefox which can still exhibit the
style=""
behaviour.)Make sure to check the dev console as there might be errors listed if this is caused by Content-Security-Policy (CSP) settings/restrictions.
CSP settings can either be specified by a
Content-Security-Policy
header in the web server's HTTP response, or they can be added with a<meta http-equiv="Content-Security-Policy" ...>
tag in the HTML (or browser extensions can also enable them on your page).我认为您无法在 td 标记内指定文本对齐方式。但是,您可以像这样设置 td 内容的对齐方式:
I don't think you can specify text alignment within a
td
tag. However, you can set the alignment of the contents of thetd
like this: