input文字垂直置中和按鈕對齊問題,相容IE8,inputie8

來源:互聯網
上載者:User

input文字垂直置中和按鈕對齊問題,相容IE8,inputie8

1、盒子模型問題:請CSS重設

2、按鈕不對齊:請浮動或者vertical-align:middle;然後計算寬高,使其對齊 ;

3、IE8文本不置中:line-height屬性     注意:IE8不支援font寫法(或者某個樣式不支援)

IE瀏覽器測試到IE8,IE5、6、7慎用。

問題原因:盒子模型

1、盒子模型:

在頁面放2個input,一個text文字框,一個button按鈕(設定寬高,無任何其他樣式)

input[type='text']{width:400px;height:45px;}

input[type='button']{width:45px;height:45px;}

觀察:IE8:文字框border:1px;padding:2px;

                按鈕border:3px;padding:1px 8px;

Firefox:文字框border:1px;padding:2px;

         按鈕border:3px;padding:0px 8px;

Google:文字框border:2px;padding:1px 0px;

        按鈕border:2px;padding:1px 6px;

添加樣式,讓border,padding一樣

input[type='text']{width:400px;height:45px;border:1px solid red;padding:0;}

input[type='button']{width:45px;height:45px;border:1px solid red;padding:0;}

觀察:

IE8:文字框border:1px;content:202x47 (IE的盒子模型)

        按鈕border:1px;content:45x45 (IE的盒子模型)

Firefox:文字框border:1px;content:200x45

       按鈕border:1px;content:43x43

Google:文字框border:1px;content:200x45

       按鈕border:1px;content:43x43

2、按鈕對齊方法:浮動(原因是Offset不同沒有搜尋更多的知識,可以自己補充這方面的知識);

input[type='text']{width:400px;height:45px;border:1px solid red;padding:0;float:left;}
input[type='button']{width:45px;height:45px;border:1px solid red;padding:0;float:left;}

參考第2步,自行計算寬高,使其對齊(有的可能沒有border,用的背景色代替,請設定border:0;高度自行調整)
input[type='text']{width:400px;height:45px;border:1px solid red;padding:0;float:left;}
input[type='button']{width:47px;height:47px;border:1px solid red;padding:0;float:left;}

3、IE8文本置中:line-height     注意   IE8不支援font寫法

將font:normal 18px "微軟雅黑";換成font-size:18px;font-style:normal;font-family:"微軟雅黑"!

或者(這樣可以用font:normal 18px "微軟雅黑";寫法,但是有點不是在正中間)
input[type='text']{width:400px;height:25px;padding:10px 0px;border:1px solid red;float:left;}
input[type='button']{width:47px;height:47px;line-height: 47px;border:1px solid red;padding:0;float:left;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.