I have an XHTML strict page that has an invisible div that is controlled by Javascript. The div is set to transparent and visible by the script and a mouseover event to make the div opaque on hover.
When someone using a browser (or firefox with noscript) without javascript the div simply remains invisible. The problem with this is that I do not want the content to be inaccessible. I also do not want to leave the div visible then use the script to make it transparent as the div is located at the bottom of the document and it causes a noticeable flicker whenever a page loads.
I have tried using noscript tags to embed an additional style sheet that is only loaded for people without the luxury of Javascript but this fails the XHTML strict validation. Is there any other way to include extra styling information inside a noscript block that is XHTML valid?
Ed:
With a simple test case I get a validation error of: document type does not allow element "style" here. This is with an empty XHTML Strict document with a style element inside a noscript element. The noscript is inside the body.
UPDATE for 2016:
From w3school:
My solution for having expanded menus (lists, etc..)
I've put in the header like this
In the
x_no_script.css
I set the selectors that I wanted toIn this way, I have expanded menus when JavaScript is disabled or not exists.
To clear up the validation issue:
noscript
is only allowed in thebody
element,style
only allowed in thehead
. Therefore, the latter is not allowed within the former.On the general issue: you'll want to make the
div
element visible by default, then hide it via CSS + javascript. This is the 'progressive enhancement' model. I notice you say you "don't want to do this because of the flicker", but I'm not sure exactly what's causing this - chances are you can fix it, so maybe you should post that as a question.Note about my answer
I wrote this post after realizing it was dating from 2008
Since I had a similar problem, I thought continuing answering with a current answer.
My actual answer
Like Boby Jack said,
style
tag is not allowed in body. I myself did the exact thing as you (Joshua) about it. But Jack's "progressive enhancement" made me without non-abstract solution but then I realized a solution that I did not find answers on this thread.It all depends of your styling structure.
My suggestion is to plainly use something like
modernizr
in the very begining of the head and use Paul Irish's HTML5Boilerplate recommendations.Long story short
class
attributes withno-js
.hide-me
) withdisplay:none
on its proper place.no-js .hide-me { display:block }
In detail
See Paul Irish's HTML5boilerplate, and adapt it to XHTML if you want :)
1. Html has a class attributes with
.no-js
quoting from
html5boilerplate.com
2. Head tag includes a first modernizr javascript as the first
Modernizr execution will build
html
attributes with what's supported.Will build something similar to this:
Note this is from Google Chrome
modernizr
tests.The first is
js
but if Modernizr did not run (no javascript) theno-js
would stay there.3. CSS has the element (
.hide-me
) withdisplay:none
on its proper place... you know the rest :)
In case XHTML is used, the trick is to use two CSS files. One global one and one js-one tweaking the global one for JavaScript-enabled browsers.
style.css:
style-js.css:
test.html:
Main idea by tutorials.de. XHTML validity tip by Estelle Weyl's Blog. createElementNS tip by CodingForums.
What validation error do you get?
<noscript>
should be allowed in XHTML but it's block level, so make sure it's not in a<p>
,<span>
, etcUse a
script
block in thehead
to add astyle
element withdocument.write
: