跨浏览器与表单的兼容性问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了跨浏览器与表单的兼容性问题相关的知识,希望对你有一定的参考价值。

我已经编写了一份客户信息表,但是在IE 8,chrome和Firefox中看起来不同。我希望它以相同的方式在所有三个浏览器中显示,如下所示。

下图显示了在其他浏览器中的外观

[1)Firefox

enter image description here


2)Chrome

enter image description here


[3)IE 8兼容模式

enter image description here


这是我的html代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org

/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Web System</title>
<link href="css/layout.css" rel="stylesheet" type="text/css" />
</head>

<body>
    <div id="header">

        <div id="headerTop">
          <p>&nbsp;</p>
          <p>&nbsp;</p>
        </div>

        <div id="headerBottom"></div>
    </div>

    <div id="wrapper">
        <div id="flags"></div>
        <div id="topLine"></div>

        <div id="information">
            <div id="welcomeText">Welcome  ADMIN, CB002813</div>
            <div id="menuSearchText">Menu Search</div>
            <div id="menuSearchTextbox"><input type="text" id="menuSearch" name="menuSearch" /></div>
            <div id="searchIcon"></div>
            <div id="helpIcon"></div>
            <div id="helpText">Help</div>
            <div id="logoutIcon"></div>
            <div id="logoutText">Logout</div>
        </div>

        <div id="navigation">
            <div id="reservations"></div>
            <div id="rentals"></div>
            <div id="tariffs"></div>
            <div id="fleet"></div>
            <div id="tools"></div>
            <div id="reports"></div>
            <div id="systemManagement"></div>
            <div id="navigationRepeat"></div>
        </div>

        <div id="customerForm">
            <div id="customerHeader"></div>
            <form>
                <div id="firstLine">
                    <div id="customerNo">Customer No.</div>
                    <input type="text" name="customerNoText" id="customerNoText" size="13" />
                    <div id="title">Title</div>                    
                        <select id="titleCombo">
                            <option value="selectTitle"></option>
                            <option value="mr">Mr.</option>
                            <option value="mrs">Mrs.</option>
                            <option value="ms">Ms.</option>
                        </select>                  
                </div>
                <div id="secondLine">
                    <div id="firstName">First Name</div>
                    <div id="firstNameMandatory"></div>
                    <input type="text" id="firstNameText" name="firstNameText" size="13"/>
                    <div id="middleName">Middle Name</div>
                    <input type="text" id="middleNameText" name="middleNameText" size="13"/>
                    <div id="lastName">Last Name</div>
                    <div id="lastNameMandatory"></div>
                    <input type="text" id="lastNameText" name="lastNameText" size="13"/>
                    <div id="searchIcon2"></div>
                </div>
                <div id="thridLine">
                    <div id="delivery">Delivery</div>
                    <select id="deliveryCombo">
                        <option value="selectDelivery">Select</option>
                        <option value="document">Document</option>
                        <option value="nonDocument">Non Document</option>
                    </select>
                    <div id="collection">Collection</div> 
                    <select id="collectionCombo">
                        <option value="selectCollection">Select</option>
                        <option value="small">Small</option>
                        <option value="large">Large</option>
                    </select>
                </div>
                <div id="fourthLine">
                    <div id="flightNo">Flight No.</div>
                    <input type="text" id="flightNoText" name="flightNoText"  size="5"/>
                    <select id="flightNoCombo">
                        <option value="selectFlightNo"></option>
                        <option value="ul209">UL 209</option>
                        <option value="ul211">UL 211</option>
                    </select>
                    <div id="terminal">Terminal</div>
                    <input type="text" id="terminalText" name="terminalText" size="13"/>
                </div>
                <div id="fifthLine">
                    <div id="specialServices">Special Services</div>
                    <select id="specialServicesCombo">
                        <option value="selectSpecialServices"></option>
                        <option value="plane">Plane</option>
                        <option value="ship">Ship</option>
                        <option value="taxi">Taxi</option>
                    </select>
                    <div id="raType">RA Type</div>
                    <select id="raTypeCombo">
                        <option value="selectRaType"></option>
                        <option value="a">A</option>
                        <option value="b">B</option>
                    </select>
                </div>
            </form>
        </div>

        <div id="bottomLine"></div>

        <div id="footer">
            <div id="footerText1">Terms and Conditions | Contact Us</div>
            <div id="footerText2">Copyright © 2010. All rights reserved. Software by EVES IT Lanka (Pvt) Ltd.</div>
            <div id="w3cLogo"></div>
        </div>

    </div>
</body>
</html>

这是我的CSS

* {
    margin: 0px;
    padding: 0px;
}
#header #headerBottom {
    background-image: url(../images/header_part2.gif);
    background-repeat: repeat-x;
    height: 6px;
    width: auto;
}
#wrapper #flags {
    background-image: url(../images/flags.gif);
    height: 37px;
    width: 960px;
    background-color: #FFF;
    background-position: 777px;
    background-repeat: no-repeat;
}
#header #headerTop {
    background-image: url(../images/header_part1.gif);
    background-repeat: repeat;
    height: 185px;
    background-position: center;
}
#wrapper #topLine {
    background-image: url(../images/line.gif);
    background-repeat: no-repeat;
    background-position: center;
    height: 5px;
    width: 960px;
}
#wrapper #informationTop #informationLeft {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    text-decoration: none;
    float: left;
    margin-left: 34px;
    margin-top: 12px;
}
#wrapper {
    background-color: #FFFFFF;
    width: 960px;
    margin-right: auto;
    margin-left: auto;
    border-right-width: 1px;
    border-left-width: 1px;
    border-right-style: double;
    border-left-style: double;
    border-right-color: #CCC;
    border-left-color: #CCC;
}
#wrapper #informationTop #informationRight #informationRightIcon {
    background-image: url(../images/help_icon.gif);
    height: 20px;
    background-repeat: no-repeat;
    float: left;
    width: 637px;
    margin-top: 7.5px;
    background-position: 617px;
}
#footer {
    margin-bottom: auto;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10px;
    text-align: center;
    padding: 10px;
}
#wrapper #footer #w3cLogo {
    background-image: url(../images/w3c_logo.gif);
    height: 31px;
    width: 960px;
    background-repeat: no-repeat;
    background-position: center;
    margin-top: 10px;
}
#wrapper #bottomLine {
    background-image: url(../images/line.gif);
    height: 5px;
    width: 960px;
    margin-top: 736px;
    background-repeat: no-repeat;
    background-position: center;
}
#wrapper #loginContainer #loginContainerMain form {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    line-height: 30px;
    padding-top: 43px;
    margin-left: 56px;
    margin-right: 40px;
    margin-bottom: 68px;
}
#wrapper #informationTop #informationRight #informationRightText {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    font-weight: bold;
    float: right;
    margin-top: 12px;
    margin-right: 22px;
}
body {
    background-color: #FFFFFF;
    background-image: url(../images/background.gif);
    background-repeat: repeat-x;
}
#wrapper #information #welcomeText {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    float: left;
    margin-left: 34px;
    margin-top: 14px;
}
#wrapper #information #menuSearchText {
    float: left;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    font-weight: bold;
    margin-left: 330px;
    margin-top: 14px;
}
#wrapper #navigation {
    background-color: #06C;
    height: 36px;
    width: 960px;
    clear: both;
}
#wrapper #information #helpText {
    float: left;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    font-weight: bold;
    margin-top: 13px;
    margin-left: 5px;
}
#wrapper #information #logoutIcon {
    background-image: url(../images/logout_icon.gif);
    float: left;
    height: 23px;
    width: 24px;
    margin-top: 8px;
    margin-left: 10px;
    margin-bottom: 12px;
}
#wrapper #information #logoutText {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    font-weight: bold;
    float: right;
    margin-top: 13px;
    margin-right: 17px;
}
#wrapper #information #menuSearchTextbox #menuSearch {
    float: left;
    margin-top: 9px;
    margin-left: 10px;
}
#wrapper #navigation #reservations {
    background-image: url(../images/reservation_button.gif);
    height: 36px;
    width: 86px;
    float: left;
}
#wrapper #navigation #rentals {
    background-image: url(../images/rental_button.gif);
    height: 36px;
    width: 124px;
    float: left;
}
#wrapper #navigation #tariffs {
    background-image: url(../images/tariff_button.gif);
    height: 36px;
    width: 59px;
    float: left;
}
#wrapper #navigation #fleet {
    background-image: url(../images/fleet_button.gif);
    float: left;
    height: 36px;
    width: 64px;
}
#wrapper #navigation #tools {
    background-image: url(../images/tools_button.gif);
    height: 36px;
    width: 56px;
    float: left;
}
#wrapper #navigation #reports {
    background-image: url(../images/reports_button.gif);
    float: left;
    height: 36px;
    width: 71px;
}
#wrapper #navigation #systemManagement {
    background-image: url(../images/systemManagement_button.gif);
    height: 36px;
    width: 135px;
    float: left;
}
#wrapper #navigation #navigationRepeat {
    background-image: url(../images/navigation_repeat.gif);
    width: 365px;
    height: 36px;
    float: right;
    background-position: right;
    background-repeat: repeat-x;
}
#wrapper #navigation {
    border: 1px solid #adb09d;
}

#wrapper #information #searchIcon {
    background-image: url(../images/search_icon.gif);
    height: 16px;
    width: 16px;
    float: left;
    margin-left: 14px;
    margin-top: 13px;
}
#wrapper #information #helpIcon {
    background-image: url(../images/help_icon.gif);
    height: 20px;
    width: 20px;
    float: left;
    margin-top: 10px;
    margin-left: 26px;
}
#wrapper #customerForm {
    height: 226px;
    width: 682px;
    margin-top: 53px;
    margin-left: 11px;
    border: 1px solid #F30;
}
#wrapper #customerForm #customerHeader {
    background-image: url(../images/customer_header.gif);
    height: 18px;
    width: 682px;
    background-position: center;
    background-repeat: no-repeat;
}
#wrapper #customerForm form #firstLine {
    height: 22px;
    width: 682px;
    margin-top: 39px;
}
#wrapper #customerForm form #secondLine {
    height: 22px;
    width: 682px;
    margin-top: 6px;
}
#wrapper #customerForm form #thridLine {
    height: 22px;
    width: 682px;
    margin-top: 6px;
}
#wrapper #customerForm form #fourthLine {
    height: 22px;
    width: 682px;
    margin-top: 6px;
}
#wrapper #customerForm form #fifthLine {
    height: 22px;
    width: 682px;
    margin-top: 6px;
}
#wrapper #customerForm form #firstLine #customerNoText {
    float: left;
    margin-left: 9px;
}
#wrapper #customerForm form #thridLine #delivery {
}
#wrapper #customerForm form #firstLine #titleCombo {
}
#wrapper #customerForm form #fifthLine #specialServices {
}

#wrapper #customerForm form #firstLine #customerNo {
    float: left;
    margin-left: 46px;
}
#wrapper #customerForm form #firstLine #title {
    float: left;
    margin-left: 70px;
    margin-right: 10px;
}
#wrapper #customerForm form #secondLine #firstName {
    float: left;
    margin-left: 60px;
}
#wrapper #customerForm form #secondLine #middleName {
    float: left;
    margin-left: 19px;
}
#wrapper #customerForm form #secondLine #firstNameMandatory {
    background-image: url(../images/mandatory_icon.gif);
    height: 8px;
    width: 8px;
    float: left;
}

#wrapper #customerForm form #secondLine #LastName {
    float: left;
}
#wrapper #customerForm form #secondLine #firstNameText {
    float: left;
    margin-left: 3px;
}
#wrapper #customerForm form #secondLine #middleNameText {
    float: left;
    margin-left: 10px;
    margin-right: 22px;
}
#wrapper #customerForm form #secondLine #lastNameMandatory {
    background-image: url(../images/mandatory_icon.gif);
    height: 8px;
    width: 8px;
    float: left;
}

#wrapper #customerForm form #secondLine #lastName {
    float: left;
}
#wrapper #customerForm form #secondLine #lastNameText {
    float: left;
    margin-left: 3px;
}
#wrapper #customerForm form #secondLine #searchIcon2 {
    background-image: url(../images/search_icon.gif);
    height: 16px;
    width: 16px;
    float: left;
    margin-left: 5px;
}
#wrapper #customerForm form #thridLine #delivery {
    float: left;
    margin-left: 77px;
}
#wrapper #customerForm form #thridLine #deliveryCombo {
    float: left;
    margin-left: 11px;
    width: 105px;
}
#wrapper #customerForm form #thridLine #collection {
    float: left;
    margin-left: 36px;
}
#wrapper #customerForm form #thridLine #collectionCombo {
    float: left;
    margin-left: 10px;
    width: 105px;
}
#wrapper #customerForm form #fourthLine #flightNo {
    float: left;
    margin-left: 70px;
}
#wrapper #customerForm form #fourthLine #flightNoText {
    float: left;
    margin-left: 10px;
}
#wrapper #customerForm form #fourthLine #flightNoCombo {
    float: left;
    width: 49px;
}
#wrapper #customerForm form #fourthLine #terminal {
    float: left;
    margin-left: 38px;
}
#wrapper #customerForm form #fourthLine #terminalText {
    margin-left: 15px;
}

#wrapper #customerForm form #fifthLine #specialServices {
    float: left;
    margin-left: 30px;
}
#wrapper #customerForm form #fifthLine #specialServicesCombo {
    float: left;
    width: 105px;
    margin-left: 11px;
}
#wrapper #customerForm form #fifthLine #raType {
    float: left;
    margin-left: 42px;
}
#wrapper #customerForm form #fifthLine #raTypeCombo {
    margin-left: 14px;
    width: 105px;
}

#wrapper #customerForm form {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}

所以有人可以指导我下一步该怎么做吗? ...........是的,我认为仅此而已。

答案

而不是使用size属性,您应该使用CSS来设置字段的宽度。另外,取决于用户代理,<input><select>元素可能使用的盒模型不同于传统的W3C“内容盒”模型。

您可以使用以下CSS在包括IE在内的所有浏览器上调整输入的大小:

input, select {
   width: 105px;
   -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
   -moz-box-sizing: border-box;    /* Firefox, other Gecko */
   box-sizing: border-box;         /* Opera/IE 8+ */
}

这将强制所有输入使用边界框模型(Quirks IE模型),并确保所有浏览器上的输入大小均相同。

另一答案

您需要使用CSS而不是INPUT属性为size=..字段设置宽度。并非所有浏览器都考虑size属性的最大允许内容和元素大小。

所以代替

<input type="text" size="7">

您需要类似的东西

<input type="text" style="width: 150px;">

((外部文件中的CSS以及其他所有内容,而不是示例中的内联。)

另一答案

也许您会发现针对浏览器的CSS黑客有所帮助:http://paulirish.com/2009/browser-specific-css-hacks/

它允许您为特定的浏览器编写单独的CSS规则,这可能是某些情况下的唯一解决方法。

以上是关于跨浏览器与表单的兼容性问题的主要内容,如果未能解决你的问题,请参考以下文章

可以采取哪些措施来避免跨浏览器兼容性问题?

PerformanceNavigation 的替代 Javascript 方法(跨浏览器兼容)

如何使模板跨浏览器兼容?

兼容ie8,firefox,chrome浏览器的代码片段

HTML 文件输入“接受”属性跨浏览器兼容性

跨浏览器自动垂直/水平居中(与Chrome和Forms兼容)