Just curious as to which is better to use in css ... width % or width in px?? Are there any known browser compatibility issues that might prompt a preference between the two?
Thank you in advance for you input. :)

Recommended Answers

All 4 Replies

Sometimes it is better to use % sometimes px.
For example. If you wish that your div has same width as page in browser than you will use %. If you wish that your div has same width as, for example, background image you have prepared for it than you will use px. Also if you have some small div that is inside of the bigger one and you wish that smaller div has same width as bigger one you will use %. If you have thumbnails placed in divs, and you wish that all thumbnails have the same width than you will use px, and also overflow:hidden.

As far as I know, all browsers recognize percentages and pixels with no problem.

I like to use percentages for page widths and such. If not, some users can have very bad experiences visiting your site.

It's a matter of preference really. Sometimes px is nice because you know the unit of measure and you don't necessarily need to make any calculations. Sometimes percentages are nice because it's generally a friendlier browser experience for "liquid" layouts.

Large areas where you know you want the width to max out the parent element you can easily use width:100%; instead of calculating the number of pixels you would have to use.

Good advise! Thanks a lot. greatly appreciated :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.