Am 12.12.11 12:48, schrieb Jukka K. Korpela:
2011-12-12 13:08, Joergen W. Lang wrote:

I've come across some sites that use the following code in the <head>
section:

<style type="text/css" style="display:none">

It would be interesting to see some sample URLs, as that could let us
find out why they are doing that.

http://www.quirksmode.org/
http://www.thecssninja.com/demo/css_chameleon/

I suspect it is there to either

a) prevent people from exposing their code

How would it do that? The contents of style elements aren't displayed on
the page by default, and they can be inspected using View Source. The
style attribute does not affect the latter at all, and regarding the
former, display: none is the default.

html, head, style {
  display: block !important;
}

shows exactly this rule in Safari 5/Mac.

I *guess* you could also use jQuery to move and change DOM nodes. But that's not the core question.

b) prevent search engines from seeing their code

How would it do that? They don't interpret styles at all.

Google states differently (http://tinyurl.com/bst65zf). They say that "Using CSS to hide text" might get the site "perceived as untrustworthy". So I conclude they must have a way to read and interpret styles.

(You could block external style sheets via robots.txt but internal/inline styles could still be read.)

Is there any documentation of this?

In HTML 4.01, a style attribute is disallowed in a <style> element. In
HTML5 drafts, it is allowed, as it is for any element. There is nothing
special here, it means the same as for any other element. But browser
behavior varies.

By default, browsers behave as if display: none were in effect for
<style> elements - and they may even have such a rule in their actual
browser style sheet. If you set the display property to some _other_
value, then the style sheet may become visible.

Using style="display: block" in a <style> element makes the style
visible on my Firefox. On IE, I need to additionally set display: block
for the <head> element. Cf. to appendix D of CSS 2.1 spec which says
head { display: none }
( http://www.w3.org/TR/CSS2/sample.html )

Similarly in Safari (see above).

One _possible_ use for <style type="text/css" style="display:none">
would be to prevent rendering of one style element's contents in a
context where it would otherwise be rendered, e.g. under the influence of

head, style { display: block; }

Acknowledged. It would make things a little tougher to add !important the the style attribute:

 <style type="text/css" style="display: none !important;" />

And even that could be overridden by a suffiently specific user style sheet (need to restart Safari be be effectice).

Still wondering why anybody would use "display: none" on a style tag,

Jørgen
______________________________________________________________________
css-discuss [css-d@lists.css-discuss.org]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/

Reply via email to