PDA

View Full Version : Browser specific style sheets


EmC
2006-02-25, 11:13
I have a web portfolio due for my teaching classes and it is really driving me crazy. It looks fine in Safari, Firefox, and Opera and then I have problems with IE. I know I need to use a separate style sheet for IE, but I can not get it to load. I have php installed on the hosting server and have tried several things found on google. The problem seems to be that there are either no instructions on how to make sure the code is actually working or the instructions are so far over my head that I have to look for an easier solution.
All I want to do is check to see if the browser is IE, if it is load msieportfoliostly.css, if not load portfoliostyle.css. This should be fairly simple right? Why the hell can't I get it to work?

lavieboheme
2006-02-25, 11:59
Why don't you try using JavaScript to identify the browser and store it as a variable, then (if, then) have it load the IE stylesheet if the browser variable is IE?

Ryan
2006-02-25, 12:28
I chose to just put a little message at the top of the page for IE browsers.

http://beniciapantherband.org

I did that using server side includes. I put

<!--#if expr="${HTTP_USER_AGENT} = /MSIE/" -->
<!--#include file="ieMessage.html" -->
<!--#endif -->

that code my index file, which calls an HTML file if the browser is IE. It isn't 100% reliable, due to browser spoofing, but I figure users smart enough to know how to use browser spoofing will know that message isn't intended for them.

rollercoaster375
2006-02-25, 15:13
Conditional comments pwn (And properly used, they're valid).


<link rel="stylesheet" type="text/css" href="/css/portfoliostyle.css" />
<!--[if IE]><link rel="stylesheet" type="text/css" href="/css/msieportfoliostly.css" /><![endif]-->


This applies a different stylesheet to IE v.5+... If you plan on supporting IE 4, you'll need to use a server side solution.

Also, the IE CSS will overlap the prior CSS... As such, the IE CSS shouldn't need to be as long.

chucker
2006-02-25, 15:19
What he said: use IE's conditional comments feature. No need for anything server-side at all, nor other sorts of trickery. Microsoft has a thorough explanation (http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp) here. Make sure you exclude IE 7 from the different stylesheet, as its CSS parser is a lot better.

EmC
2006-02-25, 15:23
Thanks guys. I got it working. The only reason I care at all about IE is that I know that the group that will be grading my web portfolio will be using IE on campus.

ast3r3x
2006-02-25, 15:31
Does<script language="PHP"> //php code </script> really work?

Brad
2006-02-25, 15:33
Does<script language="PHP"> //php code </script> really work?
I've never seen or used that before until now. No, it shouldn't work in regular HTML because PHP code cannot be parsed by web browsers. However, if it's placed in a PHP file and parsed by the web server, it should work the same as:

<?php //php code ?>

Ryan
2006-02-25, 16:38
I've never seen or used that before until now. No, it shouldn't work in regular HTML because PHP code cannot be parsed by web browsers. However, if it's placed in a PHP file and parsed by the web server, it should work the same as:

<?php //php code ?>I just read through that link I posted again and saw that. Oops. :|

ast3r3x
2006-02-25, 19:13
I didn't think that PHP would run like that Brad, but I thought I'd ask. I was wondering if there was a PHP module for apache that would parse that.

rollercoaster375
2006-02-25, 22:00
I didn't think that PHP would run like that Brad, but I thought I'd ask. I was wondering if there was a PHP module for apache that would parse that.
Yes, it's standard functionality of PHP - However, most shared hosts turn it off.

ast3r3x
2006-02-26, 07:44
Indeed you are right, what do you know. Odd that I've never seen or heard of that before. No reason for that, it's just more typing, and I'd probably more easily confuse it with my HTML.