tags:

views:

192

answers:

4

Hey SO, I am a bit rusty with my CSS, so bear with me :)

I am working with a layout that has a border-bottom property for h2,h3,h4,h5,h6. One of my pages uses h3 to display titles for a FAQ listing, and it has an anchor tag since there is an expand/contract script active (click title, FAQ appears below title). I do not want these particular h3 elements to have the border. Is there a particular CSS syntax that I can use to achieve this? maybe something like:

#content a,h3 {
    border-bottom:none;
}

This is obviously wrong since it will just clear any bottom borders for any a/h3 elements that reside in my content container.

thanks!

Clarification:

<h3><a href="#">Text</a></h3>

+1  A: 

The following is a demonstration of what each css-selector would match to. Note that it is not acceptable by web-standards to place h3's within a's.

a h3 { styles }
<a href=""><h3>Hello</h3></a>

h3 a { styles }
<h3><a href="">Hello</a></h3>
Jonathan Sampson
<h3> isn't allowed inside <a>
Greg
I was demonstrating the difference between what the selectors mean. Not suggesting he put h3's within a's.
Jonathan Sampson
A: 
#content a>h3 {  border-bottom:none; }

should do it. The > means 'next tag must be'.

#content a h3 {  border-bottom:none; }

would probably work too.

You use the comma for multiple rules e.g

h1, h2, h3 {
color: red;
}

For red h1 to h3

Meep3D
You should not have heading elements inside A tags.
Ionuț G. Stan
True, but not exactly relevant to the question.
Meep3D
Well, I don't know how relevant it is. From the question is not clear whether the As reside inside H3s or the other way around. Anyway, we shouldn't give bad practices as advice (this is relatively, as HTML5 allows A tags to contain block elements too).
Ionuț G. Stan
+7  A: 

There's no CSS selector that will select elements based on their parent. The best solution is to give the FAQ container an ID or class and then:

#faq h3 {
    border-bottom: none;
}
Ionuț G. Stan
I was wondering how long it would take for someone to post the correct answer. +1
Paolo Bergantino
So it is just my (and the other answerers) imagination that child selectors exist?
Meep3D
I figured this is what I had to do, but since my CSS isn't as it used to be (when it was simpler :P), I figured I'd ask and see if there was anything fancy I could do. Thanks!
Anders
@Meep3D, he's not looking for a child selector, but a **parent** selector, which is not available in any CSS version we know, draft or approved.
Ionuț G. Stan
@Meep3D, I made the same mistake on first reading this. While it's possible to enclose a <h*n*> element within an <a> element it's invalid (since block-level elements shouldn't be contained within inline elements), so the correct way to write the selector would be `h3 a`, this doesn't select the parent element (the <h3>).
David Thomas
+1  A: 

Use this instead :

h3>a { text-decoration: none; }

Doing so you target every 'a' childs of 'h3'

Prefer the use of classes and tags selectors versus ids the most you can, as targeting ids tend to make your css code less flexible and extensible. Think inheritance as in OOP.

For further reading and complete coverage of the CSS selectors you can refer to : http://www.w3.org/TR/2009/CR-CSS2-20090423/selector.html#child-selectors

Cheers

Peiniau