Are the decimal places in a CSS width respected?

前端 未结 6 716
别那么骄傲
别那么骄傲 2020-11-22 04:35

Something I\'ve been wondering for a while whilst doing CSS design.

Are decimal places in CSS widths respected? Or are they rounded?

.percentage {
           


        
6条回答
  •  孤城傲影
    2020-11-22 04:46

    If it's a percentage width, then yes, it is respected. As Martin pointed out, things break down when you get to fractional pixels, but if your percentage values yield integer pixel value (e.g. 50.5% of 200px in the example) you'll get sensible, expected behaviour.

    Edit: I've updated the example to show what happens to fractional pixels (in Chrome the values are truncated, so 50, 50.5 and 50.6 all show the same width).

提交回复
热议问题