如何强制
在另一个标签内使用 似乎会导致它采用自己的样式(即无),并强制内部文本采用自己的行(即使
display :inline
通过 CSS 设置)。有什么方法可以避免这种情况,或者可以使用替代方法吗?
这就是我的意思: http://www.webdevout.net/test?01I
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Test</title>
<style type="text/css">
p { font-family:sans-serif; font-size:12px;}
noscript {display:inline !important;}
</style>
</head>
<body>
<p>This is some text<noscript> that should be displayed on the same line with the same style if JS if disabled.</noscript></p>
</body>
</html>
Using <noscript>
inside of another tag seems to cause it to take on its own style (that is, none), and forces the text inside to take its own line (even if display:inline
is set with CSS). Is there any way to avoid this, or a workaround to use instead?
Here is what I mean: http://www.webdevout.net/test?01I
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Test</title>
<style type="text/css">
p { font-family:sans-serif; font-size:12px;}
noscript {display:inline !important;}
</style>
</head>
<body>
<p>This is some text<noscript> that should be displayed on the same line with the same style if JS if disabled.</noscript></p>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会推荐使用 script/noscript 标签的不同方法。
这样的效果最好:
当然,如果你使用像 jQuery 这样的框架,JavaScript 就更容易了,只需删除 JS 函数和函数体中的函数,然后只需使用以下 JS:
I would recommend a different approach over using script/noscript tags.
Something like this works best:
Of course, if you use a framework like jQuery the JavaScript is even easier, just remove the JS function and the function from the body, then just use the following JS:
老但仍然相关的问题 - http://www.tigerheron.com/article /2007/10/alternative-noscript-tag 提供了一个出色且非常简单的解决方案:
“将以下代码插入网页的
部分:
当您需要使用
内联,请改用
。”
Old but still relevant question - http://www.tigerheron.com/article/2007/10/alternative-noscript-tag presents an excellent and very simple solution:
"Insert the following code into the
<head>
section of your Web page:When you need to use
<noscript>
inline, use<span class="noscript">
instead."像这样的事情应该做你想做的事。您当然应该使用不引人注目的方法,但我想目前这已经高于标准了。
Something like this should do what you want. You should of course use unobtrusive methods instead but I guess that´s above par for now.
您是否尝试过将像 span 这样的元素放入 noscript 标记中,然后设置 Span 的样式?这是一个很遥远的事情,但可能会奏效。
或者,您可以非常具体地选择您的选择器并尝试一下。类似于
#content p noscript { display:inline !important; }
可能有效。但它也可能是无法解决的。作为最后的手段,您可以放弃 noscript 标签并放入一个跨度(或您选择的元素)并给它一个 noscript 类 - 然后删除 js 中的第一个内容。
Have you tried putting an element like a span inside the noscript tag, and then styling the span? It's a long shot, but might work.
Alternatively, get very specific with your selector and give that a shot. Something like
#content p noscript { display:inline !important; }
might work. But it might also be insoluble.As a last resort, you could ditch the noscript tag and put in a span (or your element of choice) and give it a class of noscript -- then remove that first thing in your js.