-3
Good morning! I’m creating a simple menu (header), but I can’t understand when I use px or percentage. For example: this is the header I created:
I put the following settings on it:
.header {
position: fixed;
top: 0;
width: 1919px;
height: 80px;
background: #f13c78;
In case I want this menu to work on tablet and cell phone too, so I do not know if it is right to use px there or if I should use percentage, also do not know if the resolution there is right or if everything is wrong.. please help, I know it’s a basic thing but I’m not getting it at all ;(
I think it was not explained well but my problem is: I don’t know when to use px or the percentage there in 'width' and 'height'
Please clarify your specific problem or provide Additional Details to Highlight Exactly what you need. As it’s Currently Written, it’s hard to Tell Exactly what you’re asking.
–
ready corrected, gave to understand now?
– Rodrigo Vieira
When using percentage, always look at the parent element, because it will be the reference, since the percentage must necessarily refer to the value of something, ie, as many percent of how?. Already the
px
is a fixed value that does not depend on anything.– Sam
An example: if I put a div inside a div and set 50% width on the div daughter, then she will have half the width of the div mother.
– Sam
Hi, thanks for the answer! But what about when I create a header, for example? will I have to use px? and then in a sub header I use the percentage? I don’t understand well
– Rodrigo Vieira
There’s no "required" part. You use what makes the most sense, depending on what you need to do. Want the fixed size, use
px
, or relative, use percentage (in general lines, of course, remembering that still has theem
,rem
, etc). There is no formula ready, everything depends on each case. See more: https://answall.com/q/14217/112052 | https://answall.com/q/106962/112052 | https://answall.com/a/272537/112052– hkotsubo