views:

256

answers:

3

So I want to rig up some css rules for interview transcripts. The format I have in mind looks something like this:

<h2 class="interviewer">Alice: [00:00:00]</h2>
<p>Is it ok if I ask you a question now?</p>

<h2 class="interviewee">Bob: [00:00:03]</h2>
<p>Sure go ahead.</p>

I'd like the paragraph to be a particular colour based on the class of the preceeding heading. Is there a way to do this, as it would make the html markup significantly simpler.

+4  A: 

You can use following-sibling combinator: +

h2.interviewer + p { /* style goes here */ }

Williham Totland
Still leaves you out in the cold for IE6, though...
JorenB
@JorenB: IE6 should no longer be considered. It is obsolete.
Williham Totland
I should have mentioned that I don't really care about anything except Firefox for now :)
singingfish
+3  A: 

Sure:

h2.interviewer + p {
    color: red;
}

I'm not entirely sure how to do it with multiple paragraphs though. Perhaps if you encased the entire set of paragraphs in a div:

<h2 class="interviewer">Alice: [00:00:00]</h2>
<div>
    <p>Is it ok if I ask you a question now?</p>
    <p>More text here.</p>
</div>

<h2 class="interviewee"> class="interviewee">Bob: [00:00:03]</h2>
<div>
    <p>Sure go ahead.</p>
</div>

You could then do this:

h2.interviewer + div {
    color: red;
}
Samir Talwar
+2  A: 

By the way, there are better HTML elements for displaying a conversation, like the newly introduced <dialog> tag

http://www.quackit.com/html_5/tags/html_dialog_tag.cfm

Litso
Interesting. But I also want to programatically extract only text from the interviewee from the page for further processing. This doesn't seem to have the facility to convey that relationship.
singingfish
Sure it does. You can add classes to any tag. Just do `<dt class="interviewee>Bob: [00:00:00]</dt>`.
Samir Talwar
As the linked page says, <dialog> isn't in HTML5 any more.
Matthew Wilson