Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Have a style for just one TD on a page 1

Status
Not open for further replies.

LonnieJohnson

Programmer
Apr 16, 2001
2,628
US
I am so new to CSS. I took my first class last night and love it.

I already have a couple of apps that I have built in asp.net 2.0. Now I want to add style sheets.

How do I create and apply a style to just one TD on a page?

What I am doing is trying to have a certain and consistant look to my navigation area of the page. It is a TD in a huge table. That has a body, header and left navigation sections.

Thanks in advance.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
The simplest way would be to give it an ID, for example:

Code:
<td id="nav">

then you could style it thus:

Code:
#td {
   background-color: red;
   font-weight: bold;
}

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Incidentally, using tables for layout [of non-tabular data] is really frowned upon. If your CSS/HTML skills are up to it, I'd advise removing the tables and going for a DIV-based layout.

There are plenty of references to help you online, and if you do decide to go down this route, plenty of people here who'll help you out, too :)

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Ok, this is what I tried out before I got your response.

I created this in a style sheet module.

Code:
.navbar {background-color:Maroon}

Then I put this in the html of the table that is the navigation area. (I said it was a TD but it is a table inside of a TD)
Code:
class="navbar"

Is this good business practice?

I will look into your suggestion about the div tags. Our instructor said the same thing last night.

Thanks a bunch.



ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Personally (and I know some here that would disagree with me), I would use an ID if there's no chance you would need to re-use the same style. So, if you only have one nav bar, you'd only need the style once, and so a class wouldn't strictly be necessary.

However, there are benfits of using classes (if you do change your mind and have two nav bars, there's no code to change... and also it has a lower specificity, so could be easier to override later if you need to).

At the end of the day, it's personal preference, however.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I would use an ID if there's no chance you would need to re-use the same style.

I'm the king authority on CSS, but I totally agree with you.

[monkey][snake] <.
 
There's also cases in ASP.NET where you'll have to use a class as you can't guarantee the id you use will be be output to the page (fun, isn't it?!).


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
There's also cases in ASP.NET where you'll have to use a class as you can't guarantee the id you use will be be output to the page (fun, isn't it?!).

[tongue-in-cheek]That's what you get for letting some micky-mouse environment create controls for you instead of doing the job by hand yourself[/tongue-in-cheek]

;-)

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top