我正在使用表单开发一个网站,其中一个目标浏览器很不幸是IE 6和7.我遇到了CSS和IE渲染表单元素的问题。

我已经编写了一个测试用例,也是这样的(也可以在 http:/ /xistence.osnn.net/testcases/ie67fieldset/ ):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>IE [6|7] Wha?</title>
    <style type="text/css">

    html, body, div, span, applet, object, iframe,
    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
    a, abbr, acronym, address, big, cite, code,
    del, dfn, em, font, img, ins, kbd, q, s, samp,
    small, strike, strong, sub, sup, tt, var,
    dl, dt, dd, ol, ul, li,
    fieldset, form, label, legend,
    table, caption, tbody, tfoot, thead, tr, th, td {
        margin: 0;
        padding: 0;
        border: 0;
        outline: 0;
        font-weight: inherit;
        font-style: inherit;
        font-size: 100%;
        font-family: inherit;
        vertical-align: baseline;
    }

    /* remember to define focus styles! */
    :focus {
        outline: 0;
    }

    body {
        line-height: 1;
        color: black;
        background: white;
    }

    #req fieldset {
        border: 0;
        border-top: 1px solid #000;
        padding: 0em 1em 0em 1em;
    }

    #req legend + label {
        margin-top: 0.5em;
    }

    #req legend {
        font-size: 1.2em;
    }

    #req label {
        display: block;
        background: none;
    }

    #req input, #req textarea {
        position: relative;
        display: block;
        left: 200px;
        top: -1em;
        margin-bottom: -0.3em;
    }

    #req input[type="text"], #req textarea {
        width: 300px;
    }

    #req textarea {
        height: 3.6em;
    }

    #req input[type="text"], #req textarea {
        border: 1px solid #0a0;
    }

    #req label.required + input[type="text"], #req label.required + textarea {
        border: 1px solid #a00;
    }

    #req input[type="submit"] {
        position: relative;
        top: 0;
        margin: 0;
        left: 200px;
        margin-top: 0.5em;
    }

    #req input[type="hidden"] {
        display: none;
    }
    </style>
</head>
<body>
<form id="req">
    <fieldset>
        <legend>Contact Information</legend>
        <label for="name" class="required">Name: </label> <input type="text" id="name" name="name"></input>
        <label for="phone" class="required">Phone Number: </label> <input type="text" id="phone" name="phone"></input>
        <label for="email">Email: </label> <input type="text" id="email" name="email"></input>
    </fieldset>
    <fieldset>
        <legend>Personal Info</legend>
        <label for="sports">Sports:</label> <input type="text" id="sports" name="sports"></input>
        <label for="spentonline">Hours spent online: </label> <input type="text" id="spentonline" name="spentonline"></input>
        <label for="moreinfo">Tell us about yourself: </label> <textarea id="moreinfo" name="moreinfo"></textarea>
    </fieldset>
    <fieldset>
        <input type="submit" value="Submit" />
    </fieldset>
</form>
</body>
</html>

我还拍摄了两个屏幕截图,一个是IE 7,一个是IE 8,IE 7和IE 6同意这个造型,所以我没有费心去拍摄IE 6的屏幕截图。

IE [6 | 7]:

IE 8:

之前有没有人见过这个bug?我哪里做错了?我需要删除什么才能使它在IE 6/7中工作,而不需要在输入框中输入额外的行。当fieldset上的border-top消失时,额外的行将被删除,但这不是解决方案,因为这样做会消除整个视觉分离。


它是固定的。 textarea上的margin-bottom和输入[type =&quot; text&quot;]导致IE 6/7出现渲染错误。删除那些,一切都很好。我想我可以处理页面上元素之间的额外空间!

有帮助吗?

解决方案

我看到你用

input[type="submit"]

我怀疑这是IE6支持的......您可能希望在所有字段上放置类以区分不同类型的输入。

编辑

margin-bottom: -0.3em;

您目前正在使用负边距,这通常会导致IE出现问题,因此应予以删除

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top