css修正Input标签在各种浏览器中差异

来源:岁月联盟 编辑:zhu 时间:2008-10-07
css修正Input标签在各种浏览器中差异内容简介:首先,说明一下表单标签(input、select)可能在各种浏览器中的表现差异:1.当input或select与其他标签(例如a、label)混排时,可能出现不居中的问题。2....混排时,外层标签不能控制表单标签。3.input里面输入 首先,说明一下表单标签(input、select)可能在各种浏览器中的表现差异:
1.当input或select与其他标签(例如a、label)混排时,可能出现不居中的问题。
2....混排时,外层标签不能控制表单标签。
3.input里面输入的文字行高存在差别,有空隙等等。


解析现象:
input:text特性时,
默认情况下:
1.firefox高度height为16px;IE下高度为14px;
2.字体大小为:13.3333px;
3.input存在padding值:Firefox为:padding:1px 0;IE下为:padding:1px 0 3px 0;
解决实例:如下代码:


<!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>无标题文档</title>
<style type="text/css">
body {
    font-family:"宋体";
    font-size:12px;
}

table {
    border-collapse:collapse;
    border:solid red 1px;
}
td,th {
    border:solid red 1px;
    height:40px;
}
label {
    vertical-align:middle;
}
.inputtxt {
    width:200px;
    padding:0;
    font-family:"宋体";
    font-size:12px;
    height:15px;
    line-height:15px;
    vertical-align:middle;
    border:solid #0000FF 1px;
}

</style>
</head>
<body>
<form action="#" method="post">
<table>
    <tr>
      <th width="44">firt</th>
      <td ><input name="aj" type="text" maxlength="6" class="inputtxt" />
        <label>知</label>
      <input type="text" maxlength="6" class="inputtxt" /></td>
    </tr>
    <tr>
      <th>second</th>
      <td>
        <input name="bs" type="text" maxlength="6" class="inputtxt" /></td>
    </tr>
</table>
</form>
</body>
</html>

这种情况下IE和firefox都一样了如下图:

input在浏览器中的兼容性 字体样式 浏览器高度表现 input FireFox IE6.0/IE7.0 宋体;12px 15px 13px 宋体:14px 17px 15px 宋体:16px 19px 17px

图片内容