Forum Moderators: not2easy

Message Too Old, No Replies

giving cell a margin in css

         

meanweaver

12:20 am on Aug 7, 2004 (gmt 0)

10+ Year Member



I am trying to give a cell a margin all round of 20px, I had been doing it by creating another cell with a width of 20px, I have given the an id of content but cant find how to keep contents away from the edge, heres what i tried with no luck

#content{
background-color:ffffff; left-margin:20px;
}

where am i going wrong.

Regards Ian

createErrorMsg

12:49 am on Aug 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Apply your margin to the contents of the cell (or <div>), not the cell (or <div>) itself.

So if you have a <div> containing a paragraph of text...
<div id="textbox">
<p>Here is some scintillating text.</p>
</div>

...do this in the stylsheet...

#textbox p {
margin: 20px;
}

...NOT...
#textbox {
margin: 20px;
}

I use <div> in this example because I don't generally use tables and I'm not 100% sure that cells work the same way <div>s do.

[edited by: createErrorMsg at 1:45 am (utc) on Aug. 7, 2004]

edit_g

1:01 am on Aug 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're using <div class="whatever"></div> it will refer to .whatever in your stylesheet.

If you're using <div id="whatever"> this will refer to #whatever in your stylesheet.

You can use 'class' as many times as you like in your markup but you can only ever use a unique 'id' once in your markup. Edit - So if you have a div with the id of 'blah' once you've put that in your html (<div id="blah"></div> ) you can't use that same ID for another div.

With regard to where the original poster is going wrong:

#content{
background-color:ffffff; left-margin:20px;
}

Should be:

#content { background-color:#fff; margin-left: 20px;
}

If you want the margin to apply to all sides just put 'margin: 20px;'.