• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to specify css for td element

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to specify the padding for the td elements in my table. Do I have to set a class attribute in each td element, or is there a way to specify the style of the td elements in the same class that specifies the style of the table itself? Or is there some other way?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I understand the question. You'd specify the CSS for a <td> element just like you'd specify it for a <table> element, only of course you'd put "td" instead of "table" in the selector. Am I missing something?
 
Dave Southern
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I'm thinking is... I want to be able to specify the css for all the td elements in the table in one place. I know I could set the class element for each td element individually. What I'd like to do is basically say "Hey, for each td element in this table, this is how I want the css to be."
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, yeah, that's how you do it in CSS all right. Here's a link to a CSS tutorial to get you started: http://www.csstutorial.net/

Follow the link which says "Start Learning Basic Concepts in CSS".
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wait a minute... I'm interpreting the question as if you don't know how to write a selector for td elements. That would make you somebody who basically hasn't ever used CSS, which is why I linked you to the absolute beginner tutorial. But perhaps you're asking how to write a CSS selector for td elements in a single table, and not in other tables in the same page?
 
Dave Southern
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, now I might be that much of a greenhorn - not sure.

I have a class in my css file that I'm using to style my page that defined the style for the table - and it's a fairly simple class.


Now is there a way to specify css for each td element within that table? Like a subclass to 'standardTable'?

Or can you define a class for each td element on the page and restrict it so that it only applies to the td elements that are contained in the table that has 'standardTable' as it's css class?

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's wrong with:

.standardTable td

?
 
Dave Southern
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose the only thing wrong with it is that I didn't know it was there. ;)

Yep, that's just what I was looking for - thanks!
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to have a look at that tutorial, then. CSS selectors are one of the key things to learn about the language.
 
Ranch Hand
Posts: 98
Angular Framework Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in css3 nth-child(n) selector will help to solve your problem to apply specific style for table td use following code



the above code will apply style for 2nd row all td elements in your table
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He said he wanted the style applied to each td in the table, not just those that are 2nd children. There's no need to be overcomplicated. But yes, the nth-child selector is very useful when specific children need to be selected by order.
 
reply
    Bookmark Topic Watch Topic
  • New Topic