473,763 Members | 3,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A stylesheet for IE, another one for web browsers

Hi,

Once I was happy with my new deezign[1], I noticed how bad it breaks in IE
(all versions I tried). Since IE7[2] didn't give acceptable results, I
wrote a simplified style that I would fetch to IE. How to do it is the
point of my post.

I am using for now conditional comment[3] (clean) to give IE its CSS, and a IE
parsing bug[4] (not clean) to hide the real CSS from IE:

<!--[if IE]>
<link rel="stylesheet " type="text/css" href="site-IE.css">
<script src="navbar.js" type="text/javascript"></script>
<![endif]-->
<style type="text/css"><!-- @import url(site.css) all; --></style>

I am wondering whether a better method exists, especially one that would:
* not rely on a IE bug to hide the CSS file
* not break HTML validation (no <![if !IE]>...<![endif]>)
* provide good browsers with the two alternative stylesheets
* deal with several CSSes: all pages include (by SSI) site.css (or
site-IE.css), but some also include pro.css (resp. pro-IE.css), some
others perso.css (or perso-IE.css) (if I read the specs correctly,
<link rel="alternate stylesheet" ...> cannot fulfill this requirement)

A method that solves just one of the four points above would already be
great!

[1] http://yo.dan.free.fr/
[2] http://dean.edwards.name/IE7/
[3] http://msdn.microsoft.com/workshop/a...omment_ovw.asp
[4] http://www.phoenity.com/newtedge/hide_css_ie/

PS: I take this post as an opportunity to thank those who ansered my newbie
questions a while ago, and to thank everyone who intervenes in this forum:
you are definitely helping more than one person when you answer one
question! (I have been lurking for quite a while, as obviously many others
do.)

--
Daniel Déchelotte
http://yo.dan.free.fr/
Jul 21 '05 #1
22 4965
Daniel Déchelotte <ma**********@f r.club-internet.invali d> writes:
I am using for now conditional comment[3] (clean) to give
IE its CSS, and a IE parsing bug[4] (not clean) to hide
the real CSS from IE:

<!--[if IE]>
<link rel="stylesheet " type="text/css" href="site-IE.css">
<script src="navbar.js" type="text/javascript"></script>
<![endif]-->
<style type="text/css"><!-- @import url(site.css) all; --></style>

I am wondering whether a better method exists, especially one that would:
* not rely on a IE bug to hide the CSS file
* not break HTML validation (no <![if !IE]>...<![endif]>)
* provide good browsers with the two alternative stylesheets
* deal with several CSSes: all pages include (by SSI) site.css (or
site-IE.css), but some also include pro.css (resp. pro-IE.css), some
others perso.css (or perso-IE.css) (if I read the specs correctly,
<link rel="alternate stylesheet" ...> cannot fulfill this requirement)

I have no idea whether this would work (don't have IE
handy), but what does IE make of something like this:

<!--[IF IE]>
<![IF !IE]>
<![endif]-->
baz
<!--[IF IE]>
<![endif]>
<![endif]-->

-- for everything else it's just baz surrounded by a pair of
comments?

--
Jón Fairbairn Jo***********@c l.cam.ac.uk

Jul 21 '05 #2
I suggest making a stylesheet that works in all the latest browsers. So
you don't have to do such hacks. If you can't do it then you should
practice more and change how you layout the elements.

Jul 21 '05 #3
Jón Fairbairn a écrit :

| Daniel Déchelotte <ma**********@f r.club-internet.invali d> writes:
|
| > I am wondering whether a better method exists, especially one that
| > would:
| > * not rely on a IE bug to hide the CSS file
| > * not break HTML validation (no <![if !IE]>...<![endif]>)
| > * provide good browsers with the two alternative stylesheets
| > * deal with several CSSes: all pages include (by SSI) site.css (or
| > site-IE.css), but some also include pro.css (resp. pro-IE.css), some
| > others perso.css (or perso-IE.css) (if I read the specs correctly,
| > <link rel="alternate stylesheet" ...> cannot fulfill this
| > requirement)
|
| I have no idea whether this would work (don't have IE
| handy), but what does IE make of something like this:
|
| <!--[IF IE]>
| <![IF !IE]>
| <![endif]-->
| baz
| <!--[IF IE]>
| <![endif]>
| <![endif]-->

It does exactly what one would hope! Thanks for the tip.

As for my 4th wish above, I have just read this article[1] from ALA that
states "[...] these style sheets can also be grouped together by giving
them identical title attributes.". Almost obvious, but I have already
implemented an alternate (and brain-dead) solution, based on many files and
even more @import's. ;-)

[1] http://www.alistapart.com/articles/alternate/

Quick answer to logic_earth, who wrote:

| I suggest making a stylesheet that works in all the latest browsers. So
| you don't have to do such hacks. If you can't do it then you should
| practice more and change how you layout the elements.

I agree all the more that this is a personal website and I don't have to
make it HR-friendly for another two years, so my requirements were:
* perfect in FF/Mozilla (latest version)
* very good in Opera (latest version)
* useable in IE in its latest, patched, version
* don't care about the rest (well, not really)
and I will add an "About this site" page.

Unfortunately, because of the graphical design I had in mind, I ran into
the famous "extend a DIV to 100% of the content or the viewport height,
whichever is taller" problem, and the related bugs (I chose a solution that
uses fixed positioning). Also, pure CSS menus require some specific work
for IE. So I settled for a simplified style for IE, because, as is, it was
a pain to browse my site with IE. And since it is merely a personal
website, I can afford not to change the layout just for IE.

--
Daniel Déchelotte
http://yo.dan.free.fr/
Jul 21 '05 #4
.oO(logic_earth )
I suggest making a stylesheet that works in all the latest browsers.
Quite hard to do with IE.
So
you don't have to do such hacks.
I don't consider conditional comments as hacks. They are well defined to
work in IE without side effects in other browsers.
If you can't do it then you should
practice more and change how you layout the elements.


There are too many things where IE simply fails or really screws things
up. Using CCs is a rather clean way to provide workarounds if necessary.

Micha
Jul 21 '05 #5
"logic_eart h" <Th****@gd-studio.com> wrote:
I suggest making a stylesheet that works in all the latest
browsers. So you don't have to do such hacks.


You mean stylesheets with CSS-hacks that exploit bugs in IE's CSS
parser to work around IE bugs?

Jul 21 '05 #6
On 09 Jan 2005 12:24:39 +0000, "Jón Fairbairn"
<jo***********@ cl.cam.ac.uk> wrote:
Daniel Déchelotte <ma**********@f r.club-internet.invali d> writes:
I am using for now conditional comment[3] (clean) to give
IE its CSS, and a IE parsing bug[4] (not clean) to hide
the real CSS from IE:
[...]
I am wondering whether a better method exists, especially one that would:
* not rely on a IE bug to hide the CSS file

[...]
I have no idea whether this would work (don't have IE
handy), but what does IE make of something like this:

<!--[IF IE]>
<![IF !IE]>
<![endif]-->
baz
<!--[IF IE]>
<![endif]>
<![endif]-->

-- for everything else it's just baz surrounded by a pair of
comments?


As reported, at least by Daniel, this CC attempt is "working" but it
also made me think a bit about what is really happening inside IE in
that case. Let's structure the "code" a bit at first.

1. <!--[IF IE]>
2. <![IF !IE]>
3. <![endif]-->
4. baz
5. <!--[IF IE]>
6. <![endif]>
7. <![endif]-->

I have always assumed that IE's CC evaluation is based on some form of
standard principle, similar to how conditional execution would take
place in any other "programmin g language". In which case I can not see
how that CC "code snip" could hide 'baz' from IE in the first place.

Let's send this to IE under that assumption of mine.

Line 1 will be evaluated to a BOOLEAN TRUE status.

Line 2 will start a new evaluation, which will at first
'push' the TRUE running value from Line 1 on the stack
to make room for a new running value, which will be FALSE
this time.

Line 3 "should" be the 'endif' statement for Line 2 which,
when evaluated, "should" 'pop' the stack to bring back the
original TRUE value from Line 1 as the running value.

/In which case/ Line 4. with its 'baz' lies fully open for
interpretation by IE.

After that, Line 5. and Line 6. becomes "dummies" for IE
and finally Line 7 will close the evaluation started in
Line 1.

I do fully agree with the statement that this "code snip" will present
'baz' fully undisturbed to real browsers, that part is not a problem.

But in order for it to work as expected in IE we need to assume that the
FALSE running value, that comes out of the evaluation in Line 2, will
also prohibit IE from evaluating Line 3?

In which case it will also not evaluate the 'baz' in Line 4 of course.

But then, why should it evaluate Line 5? Line 6? or even Line 7?

It would be really good, from a practical standpoint, to find a reliable
way to exclude some CSS from IE all together, but I can not make the ins
and outs of the presented "code", as seen in the light of a report that
it really does "work" as expected?

What gives?

--
Rex
Jul 21 '05 #7
Jan Roland Eriksson <jr****@newsguy .com> wrote:
As reported, at least by Daniel, this CC attempt is "working" but it
also made me think a bit about what is really happening inside IE in
that case. Let's structure the "code" a bit at first.

1. <!--[IF IE]>
2. <![IF !IE]>
3. <![endif]-->
4. baz
5. <!--[IF IE]>
6. <![endif]>
7. <![endif]-->


A possible sane explanation:

1. Conditional comments are used in a preprocessor way
2. The if/endif matching respects the type of the comment
("downlevel-hidden" vs. "downlevel-revealed")

Line 1 gives true
Look for an endif.
Output everthing inbetween.
Output line 4
Line 5 gives true
Look for an endif.
Output everthing inbetween.

Results in

8. <![IF !IE]>
9. baz
10. <![endif]>

Parse again.

Line 8 gives false
Skip to endif

Jul 21 '05 #8
Martin Bialasinski a écrit :

| Jan Roland Eriksson <jr****@newsguy .com> wrote:
|
| > As reported, at least by Daniel, this CC attempt is "working" but it
| > also made me think a bit about what is really happening inside IE in
| > that case. Let's structure the "code" a bit at first.
| >
| > 1. <!--[IF IE]>
| > 2. <![IF !IE]>
| > 3. <![endif]-->
| > 4. baz
| > 5. <!--[IF IE]>
| > 6. <![endif]>
| > 7. <![endif]-->
|
| A possible sane explanation:
|
| 1. Conditional comments are used in a preprocessor way
| 2. The if/endif matching respects the type of the comment
| ("downlevel-hidden" vs. "downlevel-revealed")
| [...]
| Parse again.

That bit seems unlikely to me (for efficiency purposes).

I agree with point 2 (if/endif matching), but I think the "preprocess or
way" thing is wrong. This is my guess:

Line 1: enter comment (depth 1) to be evaluated, look for an <![endif]-->
to close it.
2: enter comment (depth 2) to be hidden, look for an <![endif]> to close it.
3-5: hidden
6: close comment of depth 2
7: close comment of depth 1

To make a point for my case, here is some simplified code that still works:

1. <!--[if IE]>
2. <![if !IE]>
3. < -->
4. <p>Read by browsers, ignored by IE
5. <!-- >
6. <![endif]>
7. <![endif]-->

(no need for conditional comment parts at lines 3 and 5)

See it in action at http://yo.dan.free.fr/test_CC.html

Oh, wait, that does *not* invalidate your explanation. ;-) Still, I think
mine is more likely. :-P

--
Daniel Déchelotte
http://yo.dan.free.fr/
Jul 21 '05 #9
Daniel Déchelotte wrote:
I agree with point 2 (if/endif matching), but I think the "preprocess or
way" thing is wrong. This is my guess:

Line 1: enter comment (depth 1) to be evaluated, look for an <![endif]-->
to close it.
2: enter comment (depth 2) to be hidden, look for an <![endif]> to close it.
3-5: hidden
6: close comment of depth 2
7: close comment of depth 1

To make a point for my case, here is some simplified code that still works:

1. <!--[if IE]>
2. <![if !IE]>
3. < -->
4. <p>Read by browsers, ignored by IE
5. <!-- >
6. <![endif]>
7. <![endif]-->

(no need for conditional comment parts at lines 3 and 5)


I've never seen whatever information Microsoft provides about how
"conditiona l comments" *should* work and I don't have IE here to test
with but, assuming that this was implemented in some vaguely rational
manner (which I admit is a big assumption), shouldn't this simple code work:

<!--[if !IE]-->
<p>read by browsers, ignored by IE
<!--[endif]-->

Real browsers would either ignore the "conditiona l comments" or, if
they're crazy enough to implement this crock, at least realize that
they're not IE; IE would process the "conditiona l comments" and skip the
content because it *is* IE.

Am I confused?

Dave

Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2088
by: Ian Fitchet | last post by:
Hi, You'll excuse me if this has been answered before but I must have missed it on my travels: Is there a definitive style sheet with includes a definition for everything that a particular browser sets to not-null/zero/inherit? Given all the usual pixel adjustments here, browser specific bug
2
2821
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: August 28, 2002 Version: 1.15 URL: http://css.nu/faq/ciwas-aFAQ.html Maintainer: Jan Roland Eriksson <rex@css.nu> ciwas stylesheet authoring FAQ v1.15 ______________________________________________________________________
12
3704
by: Tony Carnell | last post by:
Hi, Here's a conundrum that I hope someone out there can help me solve. I've created a page to XHTML 1.0 Transitional / CSS standards using Macromedia Dreamweaver MX 2004 (and validated both with no problems). Whilst creating the page I've previewed it in IE 6, FireFox 0.8 and Opera 7.21 on my PC and the page displays perfectly (well, as perfectly as IE's implementation of CSS will allow!)
12
2046
by: MasonC | last post by:
My site pages look ok in most browsers, including Safari on the Mac. With Mac's IE 5.2 the stylesheet is ignored. I've tried both @import and <Link. Any suggestions? Second question: assuming I don't want to add styles below the @import, is there any advantage in using it? How choose between @import and <Link ?? Mason C
3
4333
by: Jamie | last post by:
Hi, Thanks for the excellent answer to my last question! One more: Does anyone have a method they follow for organizing stylesheets themselves? They seem like they can get bloated and hard to read. Aside from putting all the "h1" rules together, I haven't thought of any way to do it, if it's necessary at all. J.
0
1959
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: April 10, 2003 Version: 1.16 URL: http://css.nu/faq/ciwas-aFAQ.html Maintainer: Jan Roland Eriksson <rex@css.nu> ciwas stylesheet authoring FAQ v1.16 ______________________________________________________________________
7
2710
by: Vincent van Beveren | last post by:
Hi everyone I have a JavaScript app that creates an IFRAME through DOM (createElement('IFRAME')) However, that IFRAME does not have any content yet. alert(iframe.contentWindow.document.documentElement) gives null.
3
3303
by: gdelfino | last post by:
I have an XML file which I transform into XHTML using stylesheetA.xsl. I also have stylesheetB.xsl which transforms my XML file into an Excel XML document. As both Excel and most new browsers have a built in XSTL engine, I decided to add the stylesheet information to the original XML file. Like this <?xml version="1.0" encoding="utf-8" standalone="yes"?> <?xml-stylesheet href="stylesheetA.xsl" type="text/xsl" media="excel"?>
3
1874
by: Dave Angel | last post by:
I have implemented the 'A list apart' styleswitcher which works great. I now have: - A permanent stylesheet - A normal contrast stylesheet - A high contrast stylesheet The switcher simply switches between the normal/high sheets. HOWEVER. I now wish to add a font resizer. It needs to be able to
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10140
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9992
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5268
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.