温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Web前端绘制0.5像素方法有哪些

发布时间:2021-08-04 23:45:51 来源:亿速云 阅读:119 作者:chen 栏目:web开发

这篇文章主要介绍“Web前端绘制0.5像素方法有哪些”,在日常操作中,相信很多人在Web前端绘制0.5像素方法有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Web前端绘制0.5像素方法有哪些”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

以下纪录了比较方便的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> <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> </head> <body>     <div>         <p>点击1</p>         <p>点击2</p>     </div> </body> </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>


<!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像素方法有哪些”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

web
AI