Blogging, Microsoft, Apple Ipod, Mozilla, Google Adsense, USB Drives, Web2.0
I think anybody who is doing web scripting and web design is well aware of the CSS problems across browsers, especially in Internet Explorer (IE). This is especially true and frustrating with the CSS indentation problem. Holly ‘n John have compiled a list of Internet Explorer CSS bugs on their website if you wanted to take a look.
But if you are looking for a quick solution… then read on. I was doing a quick simple page for a friend of mine when I found myself using the <ul> tag. Check out the following screen shots.

<ul style=”margin-left:-15px; color:#3056AE”>
<li>List item 1
<li>List item 2
</ul>
The list looks perfect in Firefox, right or not? I put in “margin-left:-15px” to shift the items to the left slightly. The indentation is just nice. I love you Firefox!

However, it’s a totally different sight for Internet Explorer, the world’s most used web browser. It looks horrible. List items are shifted too much to the left, even run off the screen! I am not sure if this is a bug, or just a weird behavior.
There might be a solution… perhaps a better one in CSS, but I am not going to do too much of research in this. I prefer a quick and dirty workaround. This is what I did to fix it. At least seems to have been fixed.
1. Download PHP Browser Detection script. Oh yeah, I forgot to mention my script is coded in PHP. Save the downloaded script file as “browser_detection.php”.
2. Put the following code at the top of the existing file.
<?php
include “browser_detection.php”;
if( browser_detection( ‘browser’ ) == ‘ie’ )
$margin = “20px”;
else
$margin = “-15px”;
?>
The above code basically uses the function browser_detection to check what’s the browser type we are using, and sets the margin accordingly.
3. Change the existing code to the following.
<ul style=”margin-left:<?php echo $margin; ?>; color:#3056AE”>
<li>List item 1
<li>List item 2
</ul>
That’s it. Now view the list items in both Internet Explorer and Firefox! They look great in both! Congratulations!
Should you have a nicer solution in CSS itself, please do let me know. ![]()
Miccheng
December 27th, 2007 at 2:05 pm
That’s quite a long-winded method of solving a simple problem.
Here’s my solution:
ul, li {margin:0px; padding:0px;}
li {margin-left:15px;}
Put the margin-left requirement in the li instead of ul.
Lim Chee Aun
December 27th, 2007 at 2:12 pm
I guess you don’t have much experience in CSS eh?
A better solution is this:
List item 1
List item 2
Adjust that ‘padding-left’ to your liking. Always use both margin and padding for list. I can explain further if you’re interested.
Lim Chee Aun
December 27th, 2007 at 2:14 pm
Opps, it’s this:
<ul style="margin-left:-15px; color:#3056AE">
<li>List item 1
<li>List item 2
</ul>
Lim Chee Aun
December 27th, 2007 at 2:16 pm
ugh, paste wrong
this instead. sorry.
margin-left:-0; padding-left: 15px; color:#3056AE
Kitkat
December 27th, 2007 at 2:34 pm
Miccheng,
Thanks. I tested your solution and it works like a dream.
Lim Chee Aun,
Yes, I am a newbie in CSS! A matter of fact, I am a newbie when come to computers after all.
I have also tested your solution and it works like a dream as well. Many thanks.
Both of you are great. Now I have a quick solution to the CSS indentation problem in both IE and Firefox.
Miccheng
December 27th, 2007 at 8:05 pm
@chee aun: Good practice is to keep the tags clean of CSS codes (ie. put them in a stylesheet or within the head tag.
@kitkat: do be careful of my solution though - cos it’ll apply to all the <li> and <ul> tags.
Lim Chee Aun
December 27th, 2007 at 9:37 pm
@miccheng, I know that very well
Kitkat
December 28th, 2007 at 1:17 am
Miccheng,
Thanks for the reminder. I am well aware of that.
Yong
December 28th, 2007 at 8:20 am
Yea, when it comes to CSS rendering, IE sucks… big time.
I’ve had lots of lost hours, tweaking my sites to show up properly in IE. The problem is I do not like to use hacks or additional codes to cater just for IE.
And I hate the fact that I still need to keep IE6 on my PC for troubleshooting purposes.
Btw, cool blog, keep it up!
MerDuriaN
December 28th, 2007 at 4:47 pm
oh Don’t even know you will post this kind of article -.- Anyway if you have any good tutorial about PHP do let me know okay!!
Kitkat
December 28th, 2007 at 10:45 pm
Yong,
Too bad IE is still used by majority Internet users.
MerDuriaN,
There are tonnes of PHP tutorials on the Internet. Just google it in Google.com. Anyway, if you have any questions on PHP, simple ones, just post it here, I might be able to help you. Or I am sure some readers here are good in PHP, they should be more than glad to help a sweet young girl like you!