SnookerFan SnookerFan - 9 months ago 75
CSS Question

CSS - Percentages or Pixels?

I have been using CSS for many years now, and I have always been a 'percentage' kind of guy, as in I always define heights and widths using percentages as opposed to pixels (except, for example, when setting things such as margins, padding, etc, in which case I use pixels).

I would do something like this:

height: 99%;
width: 99%;
margin-top: 10px;

but I often see examples such as this:

height: 300px;
width: 250px;
margin-top: 10px;

My question is this: is there any benefit to using one over the other overall, and if so, what are they?

Thank you.


Answer Source

Mobile webpages. %'s rock for that. As it will (obviously) adjust to suit.

However when you want a fixed width for say example an article of text that you want displayed in a certain way, px's is the winner.

Both have many plus's and minus's over each other :)