Sunday 8 July 2012

CSS box model hack alternative


CSS box model hack alternative

The box model hack is used to fix a rendering problem in pre-IE 6 browsers on PC, where by the border and padding are included in the width of an element, as opposed to added on.

 For example, when specifying the dimensions of a container you might use the following CSS rule:


#box
{
width: 100px;
border: 5px;
padding: 20px
}


This CSS rule would be applied to:


<div id="box">...</div>

This means that the total width of the box is 150px (100px width + two 5px borders + two 20px paddings) in all browsers except pre-IE 6 versions on PC. In these browsers the total width would be just 100px, with the padding and border widths being incorporated into this width. The box model hack can be used to fix this, but this can get really messy.

A simple alternative is to use this CSS:


#box
{
width: 150px
}

#box div
{
border: 5px;
padding: 20px
}


And the new HTML would be:

<div id="box"><div>...</div></div>

Perfect! Now the box width will always be 150px, regardless of the browser!



BUDDY CHECK OUT THESE ALSO : ALL LEARNING THING , HTML , CSS , WEB FORMS ,DREAM WEAVERDTD , JAVAJAVA SCRIPT , SQL , MY SQL  , PL-SQL , PHOTOSHOP , C + + , C  , WEB PAGES , MAYAPDF FILES , EVERYTHING AVAILABLE , AJAX  , HYBERNATE , WSDL  , WAP , RUBY ON RAILS , SCALA , HTTP , HTML 5 , PROTOTYPE , Wi-MAX , FLASH , WML , RUBY , PERL ,UNIX , DLL , RSS , RADIUS , UNIX SOCKET , PYTHON , JSP , SOAP , MVC , DOT NET , PHP , ADO , ASP , J QUERY , TCP/IP , VISUAL BASIC , UML , VISUAL STUDIO , GPRS....


1 comment:

  1. Please visit http://enginegearclutch.blogspot.in/ ,here u can find all about CSS and mechanical things

    ReplyDelete