移動(dòng)端1像素問題,指的是在移動(dòng)端開發(fā)中,因?yàn)槠聊环直媛蕟栴},導(dǎo)致1像素的邊框無法正常顯示的情況。
/* css代碼 */ @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx){ /* 針對(duì)高清屏 */ .border-1px { border: none; border-top: 0.01rem solid #000; } } @media only screen and (-webkit-min-device-pixel-ratio: 3), only screen and (min-device-pixel-ratio: 3), only screen and (min-resolution: 3dppx){ /* 針對(duì)3倍屏 */ .border-1px { border: none; border-top: 0.02rem solid #000; } } @media only screen and (-webkit-min-device-pixel-ratio: 4), only screen and (min-device-pixel-ratio: 4), only screen and (min-resolution: 4dppx){ /* 針對(duì)4倍屏 */ .border-1px { border: none; border-top: 0.04rem solid #000; } }
處理方法是使用CSS3中的媒體查詢,針對(duì)不同的設(shè)備分辨率設(shè)置不同的邊框樣式,來達(dá)到1像素的邊框不變形的效果。
通過媒體查詢?cè)O(shè)置邊框的單位為rem,這樣可以根據(jù)頁面根元素的字體大小進(jìn)行變化,達(dá)到自適應(yīng)的效果。同時(shí),還需要對(duì)視網(wǎng)膜屏幕進(jìn)行特殊處理,對(duì)于2倍、3倍、4倍分辨率的屏幕,設(shè)置不同的邊框?qū)挾取?/p>