Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the measure unit set if there's nothing declared in the number value [ CSS ]

Tags:

html

css

It's much more easy to me to explain it by simple example:

<img src='...'>

img {

    margin: 30;
    width: 100;
    height: 200;
}

If there's no px or percentage declared for margin, width and height, what would be the measure unit for it then?

like image 902
bhollder Avatar asked Jan 03 '23 14:01

bhollder


1 Answers

Its much more easy to explain this with a metaphor:

You wanna buy a plate for your table in a hardware store. The service guy ask you with length and width the plate should have. You say: "100 x 200". His Face 🤔

The Problem is those units could be anything: mm, cm, px, apples. To go on with the metaphor, the browser now is the service guy and has absolute now clue what you mean with width: 100; and no value. Therefore he just take 0 = no margin because this is the default value for margin. Basically all styles that define dimensions or measurements need a value, else those are null.

According the W3C:

  • margin default value: 0
  • padding default value: 0
  • width default value: auto
  • height default value: auto

Hope this helps for understanding. A list with all default values can be found here: https://www.w3schools.com/cssref/css_default_values.asp

like image 185
Gerrit Halfmann Avatar answered Jan 06 '23 05:01

Gerrit Halfmann