Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wrong borders' width in android browser

On android devices with high density screens (devicePixelRatio of 1.5) the borders of html elements have wrong border width.

The two boxes here: jsbin sample, appear correctly on the desktop

but on the android - both in chrome and the stack browser - they look like this:

enter image description here

now i understand why they look like this, but i cannot find any CSS solution - only js.

the js solution would be to change the width and height of the elements to be odd as well as the top/left properties.

like image 458
memical Avatar asked Nov 18 '13 14:11

memical


People also ask

Why is my border style not working?

If you've set the shorthand border property in CSS and the border is not showing, the most likely issue is that you did not define the border style. While the border-width and border-color property values can be omitted, the border-style property must be defined. Otherwise, it will not render.

How do you remove border-width?

We can specify the no border property using CSS border: none, border-width : 0, border : 0 properties. Approach 1: We will give border-color, border-style properties to both headings, for showing text with border and no-border. For no border heading, we will use the border-width : 0 which will result in no border.


1 Answers

There is no standard solution, too bad.
You can make the next tricks to avoid an inconsistent displaying of borders with 1px width.

  • make colour of borders slightly transparent, i.e. with alpha <= 0.5. For example border-color: rgba(169, 0, 52, 0.5) I tested this on Android 4.4.2 Chrome & Yabrowser browsers. Works fine!;
  • make width/height of bordered element odd, and shift element position. Here you need to experiment and use JS, saying like:

    $('div.elemWithBadBorders').each(function(){
        var $el = $(this);
        var width = $el.width();
        if(width % 2 == 0){
            $el.css('width', (width+1)+'px');
        }
    });
    


  • Disable borders if showed on Retina displays or other hires screens. You need to use media query in css like this:

     @media (-webkit-min-device-pixel-ratio: 1.5) {
        div.elemWithBadBorders {
            border: none;
        }
     }
    

    where 1.5 is pixel density. On Retina displays it appears as 2

like image 131
Yan Pak Avatar answered Oct 04 '22 23:10

Yan Pak