Home > database >  what is the difference between 100 and 100px in CSS?
what is the difference between 100 and 100px in CSS?

Time:04-28

When I input

    body{
background-size:390 290;
}

it shows a different result, whereas, if i input

body{
background-size:390px 290px;
}

the result is different. I need to know what's the difference, also why it works sometimes and sometimes it doesn't.

CodePudding user response:

This is CSS:

body{
    background-size:390px 290px;
}

This is an error:

body{
    background-size:390 290;
}

Non-zero lengths require units. The CSS specification requires that browsers ignore rules which are invalid.

why it works sometimes and sometimes it doesn't.

If your page is running in quirks mode that it will emulate bugs in browsers of the Internet Explorer 4.x era and treat lengths with missing units as pixels.

Don't run pages in quirks mode as it increases inconsistencies between browsers.

Do validate your CSS and HTML.

CodePudding user response:

100 is not recognized to the browser, so if you type

body{
    background-size:390 290;
}

It is the same as letting the body style blank

CodePudding user response:

I think there should be a unit in css , 100 (without unit) means it will take the default value of body maybe h1 of p it is not recognized by css .so you have to put units Some units:

** PX= The smallest dot it can display measures about 1/100th of an inch (0.25mm)  ** Other units 1in = 2.54cm = 25.4mm = 72pt = 6pc ** To understand it more https://www.w3schools.com/cssref/css_units.asp

  • Related