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

mersyone

Registered
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...
 
Depending on the doctype, you may need to specify units (and it's good practice, anyway):

<td style="padding-left: 25px"></td>
 
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.
 
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.
 
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.
 
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.
 
Back
Top