自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

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

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

[[151618]]

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

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

常用的移動html viewport的設(shè)置如下

<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

具體意思就不多提,它就是讓頁面的高寬度即為設(shè)備的高寬像素,而為了方便繪制0.5像素的viewport的設(shè)置如下

<meta name="viewport" content="initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, user-scalable=no" />

這樣html的寬高就是設(shè)備的2倍,此時依然使用css board為1像素的話,肉眼看到頁面線條就相當(dāng)于transform:scale(0.5)的效果,即為0.5像素

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

二、采用 border-image的方式

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

  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4.     <meta charset="utf-8"
  5.     <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> 
  6.     <title>boardTest</title> 
  7.     <style> 
  8.             p{ 
  9.                 margin: 50px auto; 
  10.                 padding: 5px 10px 5px 10px; 
  11.                 color: red; 
  12.                 text-align: center; 
  13.                 width: 60px; 
  14.             } 
  15.              
  16.             p:first-child{ 
  17.                 border-bottom: 1px solid red; 
  18.             } 
  19.             p:last-child{ 
  20.                 border-width: 0 0 1px 0; border-image: url("img/line_h.gif"2 0 round; 
  21.             } 
  22.          
  23.     </style> 
  24. </head> 
  25. <body> 
  26.     <div> 
  27.         <p>點擊1</p> 
  28.         <p>點擊2</p> 
  29.     </div> 
  30. </body> 
  31. </html> 

三、采用background-image的方式

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

 

  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4.     <meta charset="utf-8"
  5.     <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> 
  6.     <title>boardTest</title> 
  7.     <style> 
  8.             p{ 
  9.                 margin: 50px auto; 
  10.                 padding: 5px 10px 5px 10px; 
  11.                 color: red; 
  12.                 text-align: center; 
  13.                 width: 60px; 
  14.             } 
  15.              
  16.             p:first-child{ 
  17.                 border-bottom: 1px solid red; 
  18.             } 
  19.             p:last-child{ 
  20.                 background-image: -webkit-linear-gradient(bottom,red 50%,transparent 50%); 
  21.             background-image: linear-gradient(bottom,red 50%,transparent 50%); 
  22.             background-size:  100% 1px; 
  23.             background-repeat: no-repeat; 
  24.             background-position: bottom right; 
  25.             } 
  26.          
  27.     </style> 
  28. </head> 
  29. <body> 
  30.     <div> 
  31.         <p>點擊1</p> 
  32.         <p>點擊2</p> 
  33.     </div> 
  34. </body> 
  35. </html> 

 

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

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

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

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

  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4.     <meta charset="utf-8"
  5.     <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> 
  6.     <title>boardTest</title> 
  7.     <style> 
  8.             p{ 
  9.                 margin: 50px auto; 
  10.                 padding: 5px 10px 5px 10px; 
  11.                 color: red; 
  12.                 text-align: center; 
  13.                 width: 60px; 
  14.             } 
  15.             p:first-child{ 
  16.                 border-bottom: 1px solid red; 
  17.             } 
  18.             p:last-child{ 
  19.                 position: relative; 
  20.             } 
  21.         p:last-child:after { 
  22.             position: absolute; 
  23.             content: ''
  24.             width: 100%; 
  25.             left: 0
  26.             bottom: 0
  27.             height: 1px; 
  28.             background-color: red; 
  29.             -webkit-transform: scale(1,0.5); 
  30.             transform: scale(1,0.5); 
  31.             -webkit-transform-origin: center bottom; 
  32.             transform-origin: center bottom 
  33.         } 
  34.          
  35.     </style> 
  36. </head> 
  37. <body> 
  38.     <div> 
  39.         <p>點擊1</p> 
  40.         <p>點擊2</p> 
  41.     </div> 
  42. </body> 
  43. </html> 
[[151619]]

<!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>

[[151619]]

 

責(zé)任編輯:王雪燕 來源: 博客園
相關(guān)推薦

2010-10-26 09:23:03

Web Service

2010-06-03 08:55:43

LINQ

2013-08-21 11:31:21

iPhone圖片方法

2009-09-18 12:29:55

2010-05-17 15:17:06

MySQL常用操作

2020-01-10 16:23:44

Springboot停止服務(wù)Java

2020-08-24 08:05:47

JavaScriptJavaScript 頁面

2009-09-09 11:24:46

PHP實現(xiàn)MVC

2021-02-26 13:20:48

Shell空行Linux

2009-08-31 09:19:31

c#隱藏窗口

2011-06-16 10:48:33

session

2010-04-30 16:22:07

Unix終端

2010-01-22 14:46:25

C++語言

2021-03-08 09:32:04

Python文件命令

2012-12-05 13:54:54

2022-02-17 09:12:55

MySQL數(shù)據(jù)庫設(shè)置變量

2009-07-20 17:07:30

提高ASP.NET性能

2009-09-18 13:36:10

2009-07-28 16:07:40

.NET圖片快速處理

2018-08-09 20:47:41

點贊
收藏

51CTO技術(shù)棧公眾號