Solutions for "H5 Development Basics" Mobile 1-pixel border problem

Source: Internet
Author: User

Since the amid Lord has raised the retina screen. Can have a lot of front-end brothers of the pixel eye, obsessive-compulsive partners days can be suffering. To draw a true 1-pixel border, the front-end apes were abused by browsers.

About what is the mobile side 1 pixel border problem, first on the two pictures, we will understand.

Figure 1

Figure 2

There are many ways to implement a 1PX border, with advantages and disadvantages, such as through the background image implementation, through Transform:scale (0.5). This implementation is realized through the Viewport+rem, the advantage is that it can adapt to the known various types of mobile phone screen, and there is no other way to change the color difficult, the problem of corner shadow failure. Disadvantage, this method is suitable for new projects, if the old project to use this method, the amount of change estimates will be relatively large.

<spanstyle= "FONT-SIZE:18PX;"><HTML>    <Head>        <title>1px question</title>        <Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8">        <Metaname= "Viewport"ID= "Webviewport"content= "initial-scale=1, maximum-scale=1, minimum-scale=1, User-scalable=no">                <style>HTML{font-size:1px;            }                        * {padding:0;margin:0;            }. Bds_b{Border-bottom:1px solid #ccc;            }. A,. b{Margin-top:1rem;padding:1rem;font-size:1.4rem;            }. A{width:30rem;            }. b{background:#f5f5f5;width:20rem;            }        </style>        <Script>                    varViewport=Document.queryselector ("Meta[name=viewport]"); //The following is based on device pixel settings viewport            if(Window.devicepixelratio== 1) {Viewport.setattribute ('content', 'width=device-width,initial-scale=1, maximum-scale=1, minimum-scale=1, User-scalable=no'); }            if(Window.devicepixelratio== 2) {Viewport.setattribute ('content', 'width=device-width,initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, User-scalable=no'); }            if(Window.devicepixelratio== 3) {Viewport.setattribute ('content', 'width=device-width,initial-scale=0.3333333333333333, maximum-scale=0.3333333333333333, minimum-scale= 0.3333333333333333, User-scalable=no'); }            varDocel=document.documentelement; varfontsize= Ten *(Docel.clientwidth/  the) + 'px'; DocEl.style.fontSize=fontsize; </Script>    </Head>    <Body>        <Divclass= "Bds_b a">The bottom edge width is virtual 1 pixels.</Div>        <Divclass= "B">The upper border width is virtual 1 pixels.</Div>    </Body></HTML></span>

Want to see the effect, directly copy the code down to the server, with mobile phone browsing can see the effect.

Solutions for "H5 Development Basics" Mobile 1-pixel border problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.