Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - How to make IE7 respect min-width

Tags:

html

css

IE7 is ignoring my min-width setting. I read that IE7 supports min-width as long as you are in Standards mode (not quirks). I specified

<!DOCTYPE html>

as my header. The markup is valid. I still can't get IE7 to respect min-width. What should I do?


Sample Code

     <table class="ProcedureTable">
        <thead>
            <tr>
                <th>column data</th>
                <th>column data</th>        
                <th>column data</th>
                <th>column data</th>
                <th>column data</th>
            </tr>
        </thead>
                    <tr class="PadColumns">
                        <td class="ExpandName">
                            column data
                        </td>

CSS

.ExpandName
{
    min-width:25em;
}
like image 203
P.Brian.Mackey Avatar asked Aug 15 '11 18:08

P.Brian.Mackey


People also ask

What does Min-width 100% do?

min-width:100% makes sure the element is at least as wide as its container. width: auto allows the element to keep its original size.

What is the difference between width and min-width in CSS?

The width declaration will be set 90% of whatever it's container width is. The min-width makes it so that element has to be at least 600px wide.

What is min-width and max width in CSS?

Max-width and min-width can be used together to target a specific range of screen sizes. @media only screen and (max-width: 600px) and (min-width: 400px) {...} The query above will trigger only for screens that are 600-400px wide. This can be used to target specific devices with known widths.


1 Answers

Ah Yes.. I ran into this a while ago

check out this link

http://blog.throbs.net/2006/11/17/IE7+And+MinWidth+.aspx

Essentially ... you need to include this shim in JS to manually hack the rule

Below is the way that I handle it tho

Just call the function onload of the body

    /*
author: Rob Eberhardt
desc: fix MinWidth for IE6 & IE7
params: none
returns: nothing
notes: cannot yet fix childless elements like INPUT or SELECT
history:
   2006-11-20 revised for standards-mode compatibility
   2006-11-17 first version
*/
function fixMinWidthForIE(){
   try{
      if(!document.body.currentStyle){return} //IE only
   }catch(e){return}
   var elems=document.getElementsByTagName("*");
   for(e=0; e<elems.length; e++){
      var eCurStyle = elems[e].currentStyle;
      var l_minWidth = (eCurStyle.minWidth) ? eCurStyle.minWidth : eCurStyle.getAttribute("min-width"); //IE7 : IE6
      if(l_minWidth && l_minWidth != 'auto'){
         var shim = document.createElement("DIV");
         shim.style.cssText = 'margin:0 !important; padding:0 !important; border:0 !important; line-height:0 !important; height:0 !important; BACKGROUND:RED;';
         shim.style.width = l_minWidth;
         shim.appendChild(document.createElement("&nbsp;"));
         if(elems[e].canHaveChildren){
            elems[e].appendChild(shim);
         }else{
            //??
         }
      }
   }
}

there is another way to do it as well

http://perishablepress.com/press/2007/01/16/maximum-and-minimum-height-and-width-in-internet-explorer/

    * html div#division { 
   height: expression( this.scrollHeight < 334 ? "333px" : "auto" ); /* sets min-height for IE */
}
like image 125
samccone Avatar answered Sep 18 '22 00:09

samccone