Some CSS Hacks

When constructing websites, there are a lot of gotchas in getting sites to work on a wide range of browsers. Below are some css hacks:

 

Minheight hack

Fixing min height in IE and firefox. This allows you to specify the minimum height of a block element. Insert relevant code into appropriate style element.

  min-height: 180px;
  height: auto !important;
  height: 180px;

Centering a div

To center a div within a page to work in all browsers, you need to add the following style attributes:

  text-align: center;
  margin: 0 auto;

Centering a table

You can center a table by adding an align=”center” however this may not work in all browsers. I prefer to keep all styling and position in a stylesheet, so to center a table using css, use the following: (note the table is belongs to a class name centered-table, you may also want to chuck “text-align: center;” in the css for a good measure).

table.centered-table {
   margin-left: auto;
   margin-right: auto;
}

You May Also Like

About the Author: rnowik

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.