We Recommend

CSS: The Definitive Guide CSS: The Definitive Guide
Provides you with a comprehensive guide to CSS implementation, along with a thorough review of all aspects of CSS 2.1. Updated to cover Internet Explorer 7, Microsoft's vastly improved browser, this new edition includes content on positioning, text wrapping (nowrap), lists and generated content, table layout, user interface, paged media, and more.


Posted By

Uzbekjon on 07/07/08


Tagged

css hack ie boxmodel


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

heinz1959
SpinZ
basicmagic


Overcoming the Box Model Hack


Published in: CSS 


If you want to specify a width to any div, do NOT specify padding or margins. Just create an inner div with no width set and specify its padding and margins instead.

  1. /*
  2.   Instead of this
  3. */
  4. #main-div{
  5. width: 150px;
  6. border: 5px;
  7. padding: 20px;
  8. }
  9.  
  10. /*
  11.   Do this
  12. */
  13. #main-div{
  14. width: 150px;
  15. }
  16. #main-div div{
  17. border: 5px;
  18. padding: 20px;
  19. }

Report this snippet 

You need to login to post a comment.