Jump to content

Is it better to use px or percent?


notclive

Recommended Posts

is it better to use percent like so:-

div.example	{text-align: center; position: absolute;    	 top: 0%; 	left: 0%; 	width: 20%; 	background: #ffffff;	border: 4px solid #111111; }

or px like so:-

div.example	{text-align: center; position: absolute;    	 top: 0px; 	left: 0px; 	width: 175px; 	background: #ffffff;	border: 4px solid #111111; }

i was thinking % because different screen resolutions may may make it look strange but some browsers may not support % correctly!!??!! any advise!!

Link to comment
Share on other sites

I'm having a similar problem with my div. The only advice I can give for the moment is... don't use percent for the width, at least. If you use % for the width, then your div with get skinnier or wider when people resize the window. So use px or em or cm for the width. For the rest, I can't really help. heh. But keep an eye on my topic here too, because our answers will probably be similar.

Link to comment
Share on other sites

You don't have to include the unit (px or %) when the value is 0 :)The difference between pixels and percentages is that using percentages, also changes the width when resizing the window, and pixels don't. Pixels are relative to the user's resolution. If a user has a higher resolution, the same amount of pixels turn out to be smaller :) With percentages it don't :)So percentages are relative to the window, and pixels to the resolution.

Link to comment
Share on other sites

Can you post your code? I don't understand :)

div.title	{text-align: center;           background: #5555ff;           position: absolute;           top:0px;            left:175px;           height: 125px;           right:0px}

with opera or firefox it makes my title whatever lengh is between 175px from the left and 0px from the right, but with internet explorer it just makes it 175px from the left and auto's the width! But it does understand the right:0px for another div.

Link to comment
Share on other sites

No, right is standardly "0" :) But its not a valid statement I think :)Use this:

div.title{text-align: center;background: #5555ff; position: absolute; top:0px; left:175px; height: 125px; width:200px}
Or whatever width you like :)
Link to comment
Share on other sites

Could you post the entire code of your page then?

body	{font: normal 16px lucida sans unicode,lucida sans,arial; 	color:black;background-color:#ffffff}div.navbar	{text-align: center; position: absolute;       top:0px;      left:0px;	width: 175px;	background: #ff4444;}a.link:link	{color: white; text-decoration: none; font: 18px }a.link:active	{color: white; text-decoration: none; font: 18px }a.link:hover	{color: black; text-decoration: none; background: white; font: 18px }a.link:visited	{color: black; text-decoration: none; font: 18px }div.title	{text-align: center; background: #5555ff; position: absolute; top:0px; left:175px; height: 125px; width:82%}div.main	{text-align:left; position: absolute; top: 125px; left: 250px; background: #eeeeee; width: 450px}div.news	{text-align:left; position: absolute; top: 125px; right: 0px; background: #eeeeee; width:200px}a.text:link	{color: black; text-decoration: underline}a.text:active	{color: black; text-decoration: underline}a.text:hover	{color: black; text-decoration: underline}a.text:visited	{color: black; text-decoration: underline}p      {color:black}h1	{color:white; text-align:center}h2	{color:blue}h3	{color:red}h4      {color:green}

Link to comment
Share on other sites

There are a few tiny things I would change, I colored them red:

body {font: normal 16px "lucida sans unicode","lucida sans",arial; color:black;background-color:#ffffff}div.navbar {text-align: center; position: absolute;      top:0px;      left:0px; width: 175px; background: #ff4444;}a.link:link {color: white; text-decoration: none; font: 18px }a.link:active {color: white; text-decoration: none; font: 18px }a.link:hover {color: black; text-decoration: none; background: white; font: 18px }a.link:visited {color: black; text-decoration: none; font: 18px }div.title {text-align: center; background: #5555ff; position: absolute; top:0px; left:175px; height: 125px; width:82%}div.main {text-align:left; position: absolute; top: 125px; left: 250px; background: #eeeeee; width: 450px}div.news {text-align:left; position: absolute; top: 125px; right: 0px; background: #eeeeee; width:200px}a.text:link {color: black; text-decoration: underline}a.text:active {color: black; text-decoration: underline}a.text:hover {color: black; text-decoration: underline}a.text:visited {color: black; text-decoration: underline}p      {color:black}h1 {color:white; text-align:center}h2 {color:blue}h3 {color:red}h4      {color:green}
Also, I would suggest replacing the colornames by the hex codes, but that is not necessary. Is there anything after these changes, that works not completely as you want it?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...