...

View Full Version : What's up with this? Anchor style overrides h1?



Deicidus
08-18-2005, 09:19 AM
Take a look at http://www.thinkdammit.net/. The title of each post is enclosed in h1 tags. The linked part is enclosed in an anchor tag. In my CSS I've styled anchor, then h1 after that. Why is the anchor tag shrinking the text?

Thanks for your help!

hemebond
08-18-2005, 09:49 AM
"A" elements haver their own default style, and in this case the anchor style has priority over the H1 because it is nested inside. You'll need to over-ride the default styles for anchors within your H1 elements.

Deicidus
08-18-2005, 10:00 AM
Ok. I did get it to work that way, but I thought there must be a better way. I thought I'd have to repeat code, but I just remembered that I can put it on the same line with a comma (never comma'd complex things before). Thanks for your help!

But I don't understand--why does a nested element override its parent when I haven't specifically defined it?

hemebond
08-18-2005, 10:19 PM
But I don't understand--why does a nested element override its parent when I haven't specifically defined it?Because user-agents (such as web browsers) supply their own stylesheets.

mrruben5
08-18-2005, 11:04 PM
Hyperlink styles are not get from their parent styles.

hemebond
08-18-2005, 11:13 PM
Hyperlink styles are not get from their parent styles.Rubbish (I think. That sentence doesn't make sense)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>66178</title>
</head>
<body>
<h1>This is <a href="">a test</a></h1>
</body>
</html>

Deicidus
08-18-2005, 11:32 PM
I tested it, you seem to be correct (that is, it works as you'd think it would). Then why was mine acting funny?

I fixed it by just swapping the anchor and h1 tags, by putting the h1 inside of the anchor.

hemebond
08-19-2005, 12:02 AM
I'm not sure, but you shouldn't put a H1 (a block element) inside an A (an inline element). You haven't changed your CSS at all?

I ran a few tests and I can't replicate the behaviour. A few notes on your markup though - it's a mess. H1 elements should not be used for post headings. You've got no semantics. You've tried to use XHTML but it's not valid and it's not being served as XHTML.

I think you should focus on your markup before worrying about style.

Deicidus
08-19-2005, 03:50 AM
I know it's a mess--it's not mine. I liked the original layout, but the code was so awful that it seemed as if it had been done poorly on purpose--empty tables, incomplete code, half-done structure/style seperation, everything.

I've been working on cleaning it up, both to preserve the layout I like and to learn more about CSS and WordPress. It'll validate when I'm through with it! :thumbsup:

Why shouldn't I use headings for post titles?

Kurashu
08-19-2005, 04:25 AM
You shouldn't use a top level heading for a post heading. I'm thinking a thrid level heading would work. Given that you have a second level heading in between the two.

Here's a quick example of what I mean...



<div id="site">
<h1><a href="#">Site Title</a></h1>
<div id="posts>
<h2><span>Posts</span></h2>
<h3>Post title</h3>
<p>Lorem ipsum and what not.</p>
<h3>Post title</h3>
<p>More lorem ipsum</h3>
</div>

<div id="another-section>
<h2><span>Another Section</span></h2>
<p>Even more Lorem ipsum</p>
</div>
</div>


Man, I can't what for XHTML 2. Not having to worry about which <h[1-6]> to use.

hemebond
08-19-2005, 04:29 AM
Why shouldn't I use headings for post titles?No no. You shouldn't use H1 elements for every title. H1 should be for the site title (like in the header), H2 for the current page and H3's etc for sections within that page.

Navigation sections and such probably shouldn't have H# elements at all.

Deicidus
08-19-2005, 05:09 AM
I see. So it's a perfect tree: title (h1), page title (h2), section headings (h3), subheadings (h4), etc. That makes sense.

I've read you shouldn't skip headings though. On my main page I've got no page title, it gooes straight to the posts. So should I skip h2 so that the structure will match the other pages?

Kurashu
08-19-2005, 05:42 AM
No. You shouldn't skip headers.

hemebond
08-19-2005, 05:47 AM
I've read you shouldn't skip headings though. On my main page I've got no page title, it gooes straight to the posts. So should I skip h2 so that the structure will match the other pages?You should put a H2 in. Are you not showing the Latest Entries?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum