Mywebdunia's Blog

Archive for November 2009

Almost every developer uses list to create a navigation, even I uses ul li’s to create a navigation. I feel its easy to create navigation with ul li’s rather than using any other tag or method.

Below is just a sample code for navigation.
<ul>
<li><a href=”#”>Link 1</a></li>
<li><a href=”#”>Link 2</a></li>
<li><a href=”#”>Link 3</a></li>
</ul>

and the css code is as below

ul {
list-style: none;
}

ul li a {
display: block;
width: 130px;
height: 30px;
text-align: center;
color: #666666;
float: left;
background: #cccccc;
border: solid 1px #333333;
margin: 30px 5px;
}

Try this code and see, you will find different output in different browsers. In mozilla you get a clear aligned menu, but when you view it in IE 6 you will find somewhat a staircase effect is been generated. Very funny right.

So to get a clear navigation, we should fix this IE bug. The easiest solution for this bug is to use a float:left; for the li element.

Just add this and you are done,
ul li {
float: left;
}

Another solution would be to add display:inline; to the enclosing li element.

Just add this code and you are done

ul li {
display: inline
}

If any problem persists do contact me or comment on this.

If you are creating a layout, with some very small heights as custom borders for elements. Usually, what you will do is you’ll just have to add height: XXpx to the style’s declarations and think that it should be fine.but check your page once in IE and you’ll probably know what is the answer.

Check out with this example

HTML Code:
<div> id=”smallHeight”</div>

CSS Code:
#smallHeight{
background: #ccc;
border: solid 1px #333;
width: 400px;
height: 2px;
margin: 30px 0;
}

Surprised to see a block with around 22px height in IE.

Well you might be thinking now how to fix this issue. Thats very simple one, we have two fixes for such IE bugs.

1 Solution:
Simply add a font-size:0 for the div, this is because IE refuses to set the font-size less than the default one. So the height of the div is set to approx 22px.

#smallHeight{
background: #ccc;
border: solid 1px #333;
width: 400px;
height: 2px;
margin: 30px 0;
font-size:0;
}

This will solve your problem.

2 Solution:
Well second solution is to set overflow:hidden for the particular div block.

#smallHeight{
background: #ccc;
border: solid 1px #333;
width: 400px;
height: 2px;
margin: 30px 0;
overflow:hidden;
}

Thats quite a very handy and a simple solution. 🙂

As we all know that min-height doesn’t work in IE 6. Say for example if your site doesn’t have much content then you web page will end up till the content is there. So if you want to set some minimum height so that the page looks good. If you set some exact height for the webpage it will lead to a problem when the content is more. So to avoid this issue, there is a solution for this min-height works with mozilla, opera, chrome, safari,IE 7, IE 8 but doesn’t work with IE 6.

So to make it work with IE 6 we need to hack it. Below is the solution for such an issue

Ex:
<div id=”container”>
Some content goes here…..
</div>

<style type=”text/css” >
#container{
min-height:300px;
}
</style>
The above code works only with mozilla, safari, chrome, opera, IE7 & 8.

Solution for IE 6:
#container{
min-height:300px;
height:auto !important; //IE hack
height:300px;
}

Thats it, so simple solution no CSS 3 required, no external javascript required. Check it out.


Categories