SVG is introduced in CSS to accommodate partial Andro instances

Source: Internet
Author: User
This article mainly and you introduced the CSS in the introduction of SVG to compatible parts of the Andro display 0.5px border example of the relevant information, small series feel very good, and now share to everyone, but also for everyone to do a reference. Follow the small series together to see it, hope to help everyone.

Objective

In the development of H5 page, found that some Andro native browser is not compatible with 0.5px border, this time it is very annoying, such as the following code:


Input {  border-bottom:0.5px solid #DCDCDC;}

Using REM to improve

Think of the way in rem, because the H5 page draws on the hand of the response pixel, according to the mobile device dpi set the root element of the font-size size, so almost all PX has been changed to REM as a unit, so as to better achieve the mobile side of the responsive pixels and Retina The performance on the screen. The code is as follows:


Input {  /* 47 is the font-size size of the page root element *  /Border-bottom:calc (1REM/47) solid #DCDCDC;}

There are some models in the test perfect display, but some still do not show, online has a post that can use pseudo-elements: before and: After the performance of 1px, and then use Transform:scaley (0.5); Make a high-level adjustment, the idea is good, but grandma a bear the INPUT element does not support pseudo-elements.

Finally, a great way to find out: using svg! in CSS

The introduction of SVG in CSS to improve

The idea is to add background-image to the element, and then put the SVG as a picture type, because the 1px on the SVG is actually only 1 physical pixels.

The implementation is simple and the code is as follows:


Input {  Background-image:url ("Data:image/svg+xml;utf8,<svg xmlns= ' http://www.php.cn/2000/svg ' width= ' 100% ' height= ' 100% ' ><line x1= ' 0 ' y1= ' 100% ' x2= ' 100% ', ' y2= ', ' 100% ' stroke= ' #dcdcdc ' stroke-width= ' 1 '/></svg> ');}

Daoteng more than this, use PHP code to convert the SVG XML code into Base64 format and try again:


<?php  Echo base64_encode ("<svg xmlns= ' http://www.php.cn/2000/svg ' width= ' 100% '" height= ' 100% ' ><line x1= ' 0 ' y1= ' 100% ' x2= ' 100% ' y2= ' 100% ' stroke= ' #dcdcdc ' stroke-width= ' 1 '/></svg> ');? >

The output is as follows:

Phn2zyb4bwxucz0nahr0cdovl3d3dy53my5vcmcvmjawmc9zdmcnihdpzhropscxmdaljybozwlnahq9jzewmcunpjxsaw5lihgxpscwjyb5mt0nmtawjscge di9jzewmcunihkypscxmdaljybzdhjva2u9jynky2rjzgmnihn0cm9rzs13awr0ad0nmscvpjwvc3znpg==

Again introduced into the CSS Background-image: (note the original UTF8 to change to base64)


Input {  Background-image:url ("Data:image/svg+xml;base64, Phn2zyb4bwxucz0nahr0cdovl3d3dy53my5vcmcvmjawmc9zdmcnihdpzhropscxmdaljybozwlnahq9jzewmcunpjxsaw5lihgxpscwjyb5mt0nmtawjscge di9jzewmcunihkypscxmdaljybzdhjva2u9jynky2rjzgmnihn0cm9rzs13awr0ad0nmscvpjwvc3znpg== ");}
Related Article

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.