web前端绘制0.5像素的几种方法_html/css_WEB-ITnose
最近完成了公司安排的移动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像素的线条和其搭配使用的背景色的图片即可
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />boardTest 点击1
点击2
三、采用background-image的方式
我这里采用的是渐变色linear-gradient的方式,代码如下
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />boardTest 点击1
点击2
linear-gradient(bottom,red 50%,transparent 50%);的意思是从底部绘制一个渐变色,颜色为红色,占比为50%,而总宽度已经设置为100%而总高度为一个像素background-size: 100% 1px;
这样显示出来就是0.5像素的线条
四、采用transform: scale()的方式
就是将绘制出来的线条的高度进行半倍的缩放,代码如下
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />boardTest 点击1
点击2

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.
