Connecting Tech Pros Worldwide Forums | Help | Site Map

css can you reference an element withen an element

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#1: Oct 1 '08
The title might not make sense, but I wasn't sure how to word it.
Lets say I have the following code (which is auto generated so I cannot supply an id or class in the caption element)
Expand|Select|Wrap|Line Numbers
  1. <table class="gv" id="gvClientTracking" >
  2. <caption >
  3. Client Sites(10)<br/>
  4. </caption>
  5. <!-- etc, assume correct table structure and closing tags -->
  6.  
I can say in CSS
Expand|Select|Wrap|Line Numbers
  1. caption
  2. {
  3.    text-align: left;    
  4. }
  5.  
But I was really wondering if I could do something like
Expand|Select|Wrap|Line Numbers
  1. #gvClientTracking caption
  2. {
  3.     text-align: left;
  4. }
  5.  
Or in some manor refer to ONLY caption elements that come inside an element with the id "gvClientTracking" (or elements with class "gv" would be ok too)

I really though I had read about this once, but cannot figure out how to look it up now.

Is that possible, or am I getting it confused with some xml styling abilities?

drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,571
#2: Oct 1 '08

re: css can you reference an element withen an element


Yes you can using CSS "selectors". Unfortunately, they only work in modern browsers and not Internet Explorer though IE7 can handle a few of them with bugs. I'm heading out the door so here's a link to the spec or you can google for a tutorial on it. Here's a link to what works in which browsers.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#3: Oct 1 '08

re: css can you reference an element withen an element


Hmm well the goodnews for me is it works in ie6/ff3/chrome.2 with the
Expand|Select|Wrap|Line Numbers
  1. .gv caption
  2. {
  3. }
  4.  
selector type. That should handle everything I need for this instance.
Reply