Box model hack
Author
Discussion

incubus

Original Poster:

8,896 posts

313 months

Thursday 11th October 2007
quotequote all
Just want to confirm something regarding the box model hack.
I have a table cell that needs to fit into a 240 px wide space. I want it to have 10px padding to the left and right.
My HTML is as follows:

<table width="240">
<tr>
<td class="td240pxBox">Some content here</td>
</tr>
</table>


...and the associated css file:

td.td240pxBox
{
width:218px;
border:1px solid gray;
padding:10px 10px;
}
td.td240pxBox
{
width:240px;
voice-family: "\"}\"";
voice-family:inherit;
width:218px;
}


Is this correct? Does it mean that in IE5.5+ and FF the "content" area of the cell will be 218px, border of 1px each side, padding of 10px each side, making the max width 240px?

Cheers.

ETA: It is tabular data I am displaying, so I'm not going to go purely css...

Edited by incubus on Thursday 11th October 17:07

cottonfoo

6,053 posts

241 months

Thursday 11th October 2007
quotequote all
I think the padding declarations are wrong. You can set them explicitly with padding-left, padding-right, or in the 4-argument version:

padding: 0px 10px 0px 10px; // top, right, bottom, left
padding: 10px 10px; // top & bottom 10px, right and left 10px

incubus

Original Poster:

8,896 posts

313 months

Thursday 11th October 2007
quotequote all
Sorry, should have specified. Need padding of 10px all round so done it as padding: 10px 10px; May change top and bottom to more at a later stage so left it as two declarations rather than as padding: 10px;

Cheers

incubus

Original Poster:

8,896 posts

313 months

Friday 12th October 2007
quotequote all
BTTT smile

Altrezia

8,743 posts

242 months

Friday 12th October 2007
quotequote all
why not just use a nice pretty div?
<div id="240box">
<p>wangs</p>
</div>

  1. 240box{
width:240px;
}
  1. 240box p{
padding:10px;
}


should be padded all round and work in both bowsers?


(not that i've checked..)

edit: hash's dont work here, so 'quote' me to see it properly

Edited by Altrezia on Friday 12th October 09:38

incubus

Original Poster:

8,896 posts

313 months

Friday 12th October 2007
quotequote all
Needs to be a table rather than a div.

In your example, wouldn't the padding mean that in FF the TOTAL width of the div (margin + border + padding + content) = 260px (i.e. 0 + 0 + 20 + 240)

jagnet

4,442 posts

233 months

Friday 12th October 2007
quotequote all
CSS hacks on the whole tend not to be effective since the introduction of IE7. Hacks rely on browser bugs, which IE7 doesn't suffer from to the degree of previous IE versions, but unfortunately it's still not nearly as capable and standards compliant as browsers such as Mozilla and Opera.

You're much better of using conditional comments to load styles for particular IE versions separately (ee www.quirksmode.org/css/condcom.html for more info on conditional comments).

Using conditional comments, you could have a style rule specifically for this table cell class specifially for IE6.