简体   繁体   中英

Applying style to Table row with tr:hover css selector is not working in IE 8 (in case of *tr>td>div>input text* mouse hover action)

Mouse over the row(tr) is applying the tr:hover rule, but in case of mouse over the tr input child text content tr:hover rule is getting applied.

I am facing this issue only in IE-8. Can any one help me to identify the root cause.

可以找到两种情况

Note: Jsfiddle

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="x-ua-compatible" content="IE=8" >
<html>
<head>
    <meta charset="utf-8">
    <style type="text/css" media="screen">
        tr{
            border-width: 0;
            margin: 0;
            padding: 0;
            background-color: transparent;
            line-height: 23px;
            height: 23px;
            vertical-align: middle;
            cursor: pointer;
        }

        table {
            border: 1px solid #d3deed;
            border-collapse: collapse;
            table-layout: fixed;
            position: relative;
            border-spacing: 0;
            width: 100%;
        }

        table thead tr {
            position: relative;
        }

        table th,
        table thead td,
        table tfoot td {
            border-width: .08em;
            padding: 2px;
            height: 16px;
        }

        table tbody td {
            border: 1px solid #d3deed;
            border-bottom-color: #d3deed;
            border-top-color: #d3deed;
        }

        table th {
            border: 1px solid #d3deed;
            border-top: 0;
            border-bottom: .24em solid #d3deed;
            border-bottom: .24em solid #d3deed;
            background-color: #e5edf5;
            color: #696969;
            font: bold 12px/1.5 'Lucida Grande', Tahoma, sans-serif;
        }

        table input{
          border-style: solid;
          background-color: transparent!important;
          border: 0;
          font: normal 12px/1.5 Arial,Helvetica,sans-serif;
          width: 100%;
          cursor: text;
          height: 1.4em;
          left: 0;
          position: relative;
          top: 0;
          vertical-align: middle;
          border-radius: 0;
          -moz-border-radius: 0;
        }

        table tr:hover {
            background-color: green!important;
        }
    </style>
</head>
<body>
    <table>
            <caption>Row hover</caption>
            <thead>
                <tr>
                    <th>header1</th>
                    <th>header2</th>
                    <th>header3</th>
                    <th>header4</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <div>
                          <input readonly="true" type="text" name="" value="dsfsdfsdfsdfdsfsdfsdfsdfdsfds">
                        </div>
                    </td>
                    <td>
                        <div>
                          <input readonly="true" type="text" name="" value="dsfsdfsdfsdfdsfsdfsdfsdfdsfds">
                        </div>
                    </td>
                    <td>
                        <div>
                          <input readonly="true" type="text" name="" value="dsfsdfsdfsdfdsfsdfsdfsdfdsfds">
                        </div>
                    </td>
                    <td>
                        <div>
                          <input readonly="true" type="text" name="" value="dsfsdfsdfsdfdsfsdfsdfsdfdsfds">
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>    
</body>

If you give up on traditional methods, use some jQuery:

$("tr").hover(
    function() {
        $(this).css('background-color','#0f0');
    }
);

Seems to be I find some thing related to this. IE 8 bug

There are a couple of issues you could look at, but the main problem seems to be the DOCTYPE .

The specified DOCTYPE targets HTML4 and refers to xhtml strict DTD; it means the document should be a valid xhtml one, and not closing the input tags is not permitted causing the browser to run in quirks mode , causing the :hover to be broken.

If you can modify it, try changing the DOCTYPE by valid ones, such as:

<!DOCTYPE html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Use the latter if you have to remain in HTML4 mode.

Also, the <meta http-equiv="x-ua-compatible" content="IE=8" > is not properly placed inside the head tag, which could also lead to rendering problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM