国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

Web前端繪制0.5像素的幾種方法

2024-07-11 08:41:47
字體:
來源:轉載
供稿:網友

最近完成了公司安排的移動web觸屏開發,期間涉及到在移動設備上顯示線條,最開始采用PC常用的css board屬性來顯示1個像素的線條,但是發現在移動設備上并不美觀,參考淘寶、京東的觸屏發現它們均是采用淺細的線條來顯示在移動設備上。

  以下紀錄了比較方便的4種繪制0.5像素線條方式

一、采用meta viewport的方式,這個也是淘寶觸屏采用的方式

常用的移動html viewport的設置如下

<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
具體意思就不多提,它就是讓頁面的高寬度即為設備的高寬像素,而為了方便繪制0.5像素的viewport的設置如下

<meta name="viewport" content="initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, user-scalable=no" />
這樣html的寬高就是設備的2倍,此時依然使用css board為1像素的話,肉眼看到頁面線條就相當于transform:scale(0.5)的效果,即為0.5像素

但是這種方式涉及到頁面整體布局規劃以及圖片大小的制作,所以若采用這個方式還是事先確定為好

二、采用 border-image的方式

這個其實就比較簡單了,直接制作一個0.5像素的線條和其搭配使用的背景色的圖片即可

<!DOCTYPE html><head>    <meta charset="utf-8">    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />    <title>boardTest</title>    <style>            p{                margin: 50px auto;                padding: 5px 10px 5px 10px;                color: red;                text-align: center;                width: 60px;            }            p:first-child{                border-bottom: 1px solid red;            }            p:last-child{                border-width: 0 0 1px 0; border-image: url("img/line_h.gif") 2 0 round;            }    </style><body>    <div>        <p>點擊1</p>        <p>點擊2</p>    </div></html>

三、采用background-image的方式

我這里采用的是漸變色linear-gradient的方式,代碼如下

<!DOCTYPE html><html><head>    <meta charset="utf-8">    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />    <title>boardTest</title>    <style>            p{                margin: 50px auto;                padding: 5px 10px 5px 10px;                color: red;                text-align: center;                width: 60px;            }            p:first-child{                border-bottom: 1px solid red;            }            p:last-child{                background-image: -webkit-linear-gradient(bottom,red 50%,transparent 50%);                background-image: linear-gradient(bottom,red 50%,transparent 50%);                background-size:  100% 1px;                background-repeat: no-repeat;                background-position: bottom right;         </style></head><body>    <div>        <p>點擊1</p>        <p>點擊2</p>    </div></body></html>

linear-gradient(bottom,red 50%,transparent 50%);的意思是從底部繪制一個漸變色,顏色為紅色,占比為50%,而總寬度已經設置為100%而總高度為一個像素background-size:  100% 1px;

這樣顯示出來就是0.5像素的線條

四、采用transform: scale()的方式

就是將繪制出來的線條的高度進行半倍的縮放,代碼如下

<!DOCTYPE html><html><head>    <meta charset="utf-8">    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />    <title>boardTest</title>    <style>            p{                margin: 50px auto;                padding: 5px 10px 5px 10px;                color: red;                text-align: center;                width: 60px;            }            p:first-child{                border-bottom: 1px solid red;            }            p:last-child{                position: relative;            }            p:last-child:after {                position: absolute;                content: '';                width: 100%;                left: 0;                bottom: 0;                height: 1px;                background-color: red;                -webkit-transform: scale(1,0.5);                transform: scale(1,0.5);                -webkit-transform-origin: center bottom;                transform-origin: center bottom            }            </style></head><body>    <div>        <p>點擊1</p>        <p>點擊2</p>    </div></body></html>

 以上就是小編為大家整理出來的Web前端繪制0.5像素的幾種方法,希望對大家的學習能夠起到幫助~

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 望城县| 卢氏县| 道孚县| 绥芬河市| 建始县| 和平区| 岳池县| 阿图什市| 香格里拉县| 连江县| 精河县| 东城区| 深水埗区| 蒙城县| 且末县| 兴仁县| 三亚市| 灌南县| 建水县| 临猗县| 临桂县| 宿迁市| 孝感市| 台北市| 滦南县| 博湖县| 哈巴河县| 鹿邑县| 汶上县| 泰来县| 江山市| 福建省| 吉木萨尔县| 高邮市| 库尔勒市| 尤溪县| 隆安县| 涿州市| 建始县| 遵义市| 蓬安县|