eire web design home page contact eire-web design eire web design and development site map
stepping on in business
• Welcome to Eire Web Design Ireland

Archive for the ‘CSS’ Category

CSS Hack !important

Monday, October 15th, 2007

In CSS is very easy to overwrite a rule you have created earlier, then you wonder why making changes to the rule doesn’t  apply to the page layout. 
One thing to know is the !important rule available since CSS1.
Adding !important after a command like this:

.div { margin-left: 5px;color:#ff0000!important;margin-left: 3px;}

will make sure that all browsers  will have a margin-left of 5px regardless of what appears after it, except IE (Internet Explorer)  which ignores the !important command gives a margin-left of 3px.

This can be very useful when you need to set relative margin as the display will differ from browser to browser.

IE, however, will respect the !important declarations if they are not in the same rule as below:

.div_font {color: red;!important;}
.div_font { color: blue; }

So whatever you asign this rule to the font color will be red not blue as in the second command. 

The first example above was a very useful CSS Hack for IE, however since IE7 has been released, the !important rule doesn’t have much effect any longer, as IE7 renders the page much like Firefox.

CSS Centering fixed-width layouts

Monday, October 15th, 2007

Do you ever wonder how you can center a containing div?
The use of “tables” or “center” tag makes the job a lot easier, but it will fail validation.
Another way of doing this is using CSS stylesheet.

body{padding:0px; margin:0px; text-align:center;}

#div_container{margin-left: auto;margin-right: auto;width:800px;}

The only problem with the above solution is that “#div_container” will also have the text centered.
To overcome this problem you have to specify the “text-align” tag as below:

body{padding:0px; margin:0px; text-align:center;} #div_container{margin-left: auto;margin-right: auto;width:800px;text-align:left;}

W3C Visual formatting model explains: “If both ‘margin-left’ and ‘margin-right’ are ‘auto’, their used values are equal.
This horizontally centers the element with respect to the edges of the containing block.”

Links...

Chicklets...
  • http://www.eire-webdesign.ie/blog/feed/
    http://www.eire-webdesign.ie/blog/feed/
    Google Reader or Homepage
    Add to My Yahoo!
    Subscribe with Bloglines
    Subscribe in NewsGator Online
    add to msn
    Add to My AOL
    Add to Technorati Favorites!
    pageflakes
    windows live