How to emulate min-width in IE8

冷暖自知 提交于 2019-12-08 19:14:26

问题


The IE8 documentation says it supports min-width, but it doesn't seem to work for me.

The html I want to be a minimum width is in table cells.

I saw another question here which suggested adding a 1-pixel height div to each cell, with a width setting, but that doesn't work - IE renders it as 18 pixels high, for some reason.

Here is the html code:

<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
<style type="text/css">
table.keyboard div.key {
    height: 50px;
    font-size:50px;
    border: 5px outset gray;
    min-width: 60px;
    text-align: center;
}
table.keyboard div.spc {
    height: 1px;
    width: 60px;
    background-color: green;
}

table.keyboard td:hover {
    background-color: lightblue;
}
table.keyboard {
    border: 3px inset blue;
}
</style>
</head>
<body>
<div id="body">
<div>Here is some stuff</div>
<table class='keyboard'>
    <tbody>
        <tr>
            <td><div class='key'>1</div><div class='spc'></div></td>
            <td><div class='key'>2</div><div class='spc'></div></td>
            <td><div class='key'>3</div><div class='spc'></div></td>
            <td><div class='key'>4</div><div class='spc'></div></td>
            <td><div class='key'>5</div><div class='spc'></div></td>
        </tr>
    </tbody>
</table>
</div>
</body>
</html>

The "spc" div appears 18 px high!

Of course, if min-width worked, I wouldn't need the div...

<table class='keyboard'>
    <tbody>
        <tr>
            <td><div class='key'>1</div></td>
            <td><div class='key'>2</div></td>
            <td><div class='key'>3</div></td>
            <td><div class='key'>4</div></td>
            <td><div class='key'>5</div></td>
        </tr>
    </tbody>
</table>

Any clues?

Just to make this easier, I have put 3 different versions of this code on my website.


回答1:


http://jsfiddle.net/3htmA/

IE8. your code works perfect.




回答2:


The HTML TABLE spec uses COL to define column widths. See the following spec: http://www.w3.org/TR/html4/struct/tables.html#h-11.2.4

Here's an example of how it's used: http://www.htmldog.com/guides/htmladvanced/tables/

Min-width on table cells works differently than block-level elements. Table cells are controlled on the column level, not on the individual cell level. If a given cell size increases or decreases, the entire column will be affected, unless explicitly controlled by the tag.




回答3:


Try this:

table.keyboard .key
{
min-width:60px;
width: expression(this.width < 60 ? 60: true);
}

This width expressions is an alternative for min-width, it supposed to be a workaround for older versions of IE.

I think your problem is that your column is determining the width of the element, not the div.

EDIT:

Also check if your browser is not in Compatibility mode.



来源:https://stackoverflow.com/questions/8098758/how-to-emulate-min-width-in-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!