Forum Moderators: not2easy

Message Too Old, No Replies

CSS % and px

         

angel777

8:23 am on Oct 20, 2008 (gmt 0)

10+ Year Member



Hi can i use the % and px at the same time?
i used PX throughout my code. However, when i face the viewing in resolution 1024 and 1280, i try solve that by using width=100%. But i do not want to change my existing code.
Can i do that ?

essiw

1:32 pm on Oct 20, 2008 (gmt 0)

10+ Year Member



what do you mean? you mean that you want to put this: width="100" and width="800px" in one tag? just think, the browser can not decide which one to chose...

swa66

4:02 pm on Oct 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Something like

.myname {
width: 20px;
height: 20%;
}

will work fine.

Even
.myname {
width: 20px;
width: 20%;
}
is deterministic: the browsers will use the second value.

The one thing you cannot do is to use both at the same time. E.g. there's no way to say 20% minus 20px. If you need that, approach the problem from another side and use e.g. a parent to help or a width of 20% and use 20px padding.

angel777

1:33 am on Oct 21, 2008 (gmt 0)

10+ Year Member



what if i have this
<table width= 100%.. >

<td width= 20px >
can i ?

bonagiri

1:00 pm on Oct 21, 2008 (gmt 0)

10+ Year Member



Yes you can.

It works fine.

But I don't know adv and disadv of using it...

lexipixel

9:02 pm on Oct 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<table style="width:100%;" border="1">
<tr>
<td width="50">This</td>
<td width="50">That</td>
<td>Other</td>
</tr>
</table>

Should give you a table 100% the width of the screen, the first two columns will be 50 pixels wide, the third column will use up the rest of the width of the screen.