# How Do I...HTML <td> Styles ???



## mersyone (Mar 14, 2007)

Hello All!
So I've been recently trying out HTML coding on my own, learning something new everyday.  But, I'm at a point where I don't understand why the "style" attributes" for the <td> tag aren't working anymore.

I'm just trying to put padding on some table cells to fix some alignment issues.  I've used the "style" attribute before (e.g. <td style="padding-left:25"></td>), but now it seems to not be working.  I am not doing anything different.

Can this maybe be affected by it's "parent" tag (like <table>)?
OR I was also thinking it might be the !DOCTYPE that's causing it.
...I just don't understand.

Any help...


----------



## rwilkerson (Mar 14, 2007)

Depending on the doctype, you may need to specify units (and it's good practice, anyway):

<td style="padding-left: 25px"></td>


----------



## SourDieseL (Mar 14, 2007)

I guess I'll try to give this a shot and be somewhat helpful, but if i'm confusing, just ignore me all together! lol

if you are trying to apply a style to a specific Table, Table Row, Table Data, or any container in html, it's best to set those styles in the sheet and declare them between the head and the body or initially when you start your code.  I was never a fan of assigning style attributes directly in my html, i find it easier to reference a style by class in html rather than specify the actual style and attributes in the html.  did i confuse you yet?

i semi understand what you are getting at but think it's better to declare the table style and class reference it.  the above code looks to work but only for one cell of the table.  a good practice is to literally draw out on paper with a pen the table, dimensions, and the styles you wish to apply to each cell.  by identifying them on paper and pen, you can then declare them and class reference them since it's more than likely that more than one cell will have the same attributes.


----------



## mersyone (Mar 16, 2007)

SourDieseL said:


> i find it easier to reference a style by class in html rather than specify the actual style and attributes in the html.  did i confuse you yet?  you can then declare them and class reference them since it's more than likely that more than one cell will have the same attributes.



I do use "classes".  ...but wayyy too much!  I just often notice there are specific table cells (<td>) that just need some quick "custom-fitting" I guess you can call it.  So yes, I do use classes, but it just got annoying making a class to use only once.  So by the time I want to reuse that one class, I've already forgotten the class name (and what it did) anyways (grrr!).  

I am slowly learning to skim down on classes; Using, for example, a class for LEFT PADDING, RIGHT, BOTTOM TOP, LEFT & RIGHT, BOT & TOP, etc.  I dunno though, if you have a more efficient technique, I'd love to hear.

Thank you.


----------



## mersyone (Mar 16, 2007)

rwilkerson said:


> Depending on the doctype, you may need to specify units (and it's good practice, anyway):
> 
> <td style="padding-left: 25px"></td>



That's it.  That's all it was!  ...works like a charm.
Thankx.


----------



## SourDieseL (Mar 16, 2007)

I dont have a specific technique perse but if you practice declaring then referencing in my mind it helps keep your code clean.  By declaring these style attributes to be used down in the actual code you are essentially starting a stylesheet.  You should try that method rather then the quick style fix because in the end you'll want to add styles for your fonts, table formats, borders, margins, etc and the best way is declaring and referencing imho.


----------



## Natobasso (Mar 19, 2007)

Yes; CSS would be much better for this in the long run.


----------



## billbaloney (Mar 19, 2007)

The total separation of structure and presentation is the standard practice these days.  That means, in the ideal version of an HTML page, the tags are devoid of any indication of how they are to be displayed; all of the display information is specified in the CSS.  This means no CSS in your HTML, ever.

If you're just starting out with HTML this can seem like an awfully tall order, but it becomes easier as you gain experience, and eventually becomes the default way you construct a page.

Need inspiration?  Walk through the Zen Garden.


----------

