in CSS if you set something with a number without giving this number a unit, what would normally be the default unit ... for instance if i have:
p
{
padding: 5;
}
what would that 5 mean by default ?
i am asking this question, because i had set all my measures like the above, and now the CSS Validator says, that they should be given a unit, so i would like to just give them the unit and leave the values as they are.
Thank YouProbably pixels, e.g.: padding: 5px;thank youHi!
If you want to check, how different browsers deal with it, just put that:
<div style="width:500;" onclick="alert(this.style.width)">blah</div>
into a little .htm file. Provided that you are not using a browser with js disabled and that the browser is not toooo old, the alert will tell you something. IE and Mozilla will automatically add 'px' behind the '500' in the alert. Other browsers act differently, but display a width of 500 pixels as well.
Cheers - PitIn fact there is no default unit according to the CSS specification. If you pass your styles through the CSS validator it will alert you to this error. There must always be a unit (with the exception of 0, because 0px, 0pt, 0cm, 0em, etc. all represent the same value).In my experience, I have forgotten to put units after numbers several times. And, each time, the page did not display right. So, I don't think the browsers deal with a number the same as they do a number with the "px" unit.
Jeff Mott's answer is what I have experienced: the only number that doesn't need units is 0.Originally posted by mercury7
Jeff Mott's answer is what I have experienced: the only number that doesn't need units is 0. That's definately true, but the main browsers interprete a number in css properties as px even though it is not valid. This does not necessarily prevent them from putting out something odd.
Cheers - Pitbut the main browsers interprete a number in css properties as px even though it is not validOnly when in quirks mode. In standards compliance mode the value is interpreted as invalid and the entire property is ignored.thank you all for your replies. However, due to the fact that i have omitted the unit after each value, do you think i should add a unit to them (maybe px) since the CSS Validator has reported them as errors ?
Thank YouDo you really mean to ask us, now that you know that your CSS is wrong and you know what right would look like, if you should do it right?Yes, you should add the unit "banana" 100banana in width, of course you should add the units unless you are working in 'pear' units for the CSS.
p
{
padding: 5;
}
what would that 5 mean by default ?
i am asking this question, because i had set all my measures like the above, and now the CSS Validator says, that they should be given a unit, so i would like to just give them the unit and leave the values as they are.
Thank YouProbably pixels, e.g.: padding: 5px;thank youHi!
If you want to check, how different browsers deal with it, just put that:
<div style="width:500;" onclick="alert(this.style.width)">blah</div>
into a little .htm file. Provided that you are not using a browser with js disabled and that the browser is not toooo old, the alert will tell you something. IE and Mozilla will automatically add 'px' behind the '500' in the alert. Other browsers act differently, but display a width of 500 pixels as well.
Cheers - PitIn fact there is no default unit according to the CSS specification. If you pass your styles through the CSS validator it will alert you to this error. There must always be a unit (with the exception of 0, because 0px, 0pt, 0cm, 0em, etc. all represent the same value).In my experience, I have forgotten to put units after numbers several times. And, each time, the page did not display right. So, I don't think the browsers deal with a number the same as they do a number with the "px" unit.
Jeff Mott's answer is what I have experienced: the only number that doesn't need units is 0.Originally posted by mercury7
Jeff Mott's answer is what I have experienced: the only number that doesn't need units is 0. That's definately true, but the main browsers interprete a number in css properties as px even though it is not valid. This does not necessarily prevent them from putting out something odd.
Cheers - Pitbut the main browsers interprete a number in css properties as px even though it is not validOnly when in quirks mode. In standards compliance mode the value is interpreted as invalid and the entire property is ignored.thank you all for your replies. However, due to the fact that i have omitted the unit after each value, do you think i should add a unit to them (maybe px) since the CSS Validator has reported them as errors ?
Thank YouDo you really mean to ask us, now that you know that your CSS is wrong and you know what right would look like, if you should do it right?Yes, you should add the unit "banana" 100banana in width, of course you should add the units unless you are working in 'pear' units for the CSS.