Browsers truncate border values to integers

前端 未结 2 1999
执笔经年
执笔经年 2021-02-19 02:24

Whenever a non-integer pixel value is used for the border of an element, the browser simply truncates the value to become an integer. Why is this the case?

I\'m aware th

2条回答
  •  萌比男神i
    2021-02-19 03:21

    As far as I can tell from a few simple tests, subpixel border widths work exactly as they should. I think a typo in you example ("border-top-width" vs. "border-left-width") may be the cause of the discrepancy. This example works as expected for me:

    var div = document.getElementsByTagName("div");
    for (var i = 0; i < div.length; i++)
    {
        div[i].innerHTML += getComputedStyle(div[i]).getPropertyValue("width");
    }
    DIV
    {
        width: 300px;
        border: 1px solid black;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }
    DIV.subpixel
    {
        border-width: 1.23px;
    }
    border-width: 1px
    width:
    border-width: 1.23px
    width:

提交回复
热议问题