How to Use CSS to Solve min-width Problems in Internet Explorer
The basic idea is to feed browsers that understand min-width the normal method (as follows) and to also feed Internet Explorer it's own special styling (which I'll explain in the following tutorial).
body - general body styling
- background: #fff url(rule.gif) 20px 0; - shows the background grid (10 pixel and 100 pixel marks).
- color: #000; - sets the font color to black.
- font-family: "trebuchet ms", "times new roman", times, serif; - sets up the font choice.
- margin: 20px; - sets the margin to 20 pixels.
- padding: 0; - sets the padding to zero.
.width - the outer div that controls the width and min-width for browsers that understand this (or just the width for Internet Explorer).
- width: 50%; - the preferred width.
- min-width: 300px; - the minimum width allowed.
- background: #fff; - sets the background color to white.
.content - The container for the content in which you can add a border and/or padding while not affecting the width and min-width.
- border: 1px solid #c00; - adds a red 1 pixel solid border.
- padding: 5px; - sets the padding to 5 pixels.
.rule - Includes a rule line to show when min-width has been reached.
- width: 300px; - sets the width to 300 pixels.
- background: #c00; - makes the background dark red.
- color: #fff; - makes the text color white.
- margin: 1em 0; - adds a top and bottom margin of 1em.
If you try the above example in any browser except Internet Explorer and resize your window, the outer container will shrink until it reaches the minimum width of 300 pixels and then it will remain at this fixed width.
For Internet Explorer only
The following steps will show how to make Internet Explorer fall into line with the conforming browsers.
The general idea is to use a div with a left border width set to the same value as the minimum width. The theory is that borders of divs will not normally shrink once the body of the div has reached zero width.
To make sure that all other browsers will ignore this extra styling we will target Internet Explorer using the normal hack of preceding the style with '* html'.
We'll add this extra div with the class .minwidth
- border-left:300px solid #800; - sets the left border to 300 pixel solid dark red so that it can be seen.
All these steps will only be visible in Internet Explorer; other browsers will continue to see min-width correctly implemented.
The above example shows the left dark red border set at 300 pixels wide and the text to the right on a white background. Reducing the width of the browsers window will shrink the text width to a minimum but will not shrink the border.
We now need to move the text left by 300 pixels so that it occupies the border width as well as the normal width. This can be done by adding another div with a left margin set to -300 pixels.
- margin-left:-300px; - set the left margin to -300 pixel so that the contents will move over the border area.