By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,179 Members | 2,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,179 IT Pros & Developers. It's quick & easy.

Indenting headings and adjacent siblings?

P: n/a
I have a complex document that goes several heading levels deep, and
it's unreadable with all the headings and paragraphs against the left
margin. I'd like to indent H2 elements by 50 pixels, H3 elements by
100 pixels, and so on. The tricky part is that I need to get the
paragraphs following each heading as well.

Grouping everything in a DIV isn't an option for me, because I'm not
the one generating the HTML (It's being done by a POD to HTML
converter: http://search.cpan.org/dist/Pod-HtmlEasy/).

Here's the "solution" I came up with using adjacent selectors:

.pod H2,
.pod H2 + *,
.pod H2 + * + *,
[snip]
.pod H2 + * + * + * + * + * + * + * + * + *,
.pod H2 + * + * + * + * + * + * + * + * + * + * { margin-left: 50px;
}
.pod H3,
.pod H3 + *,
.pod H3 + * + *,
[snip]
.pod H3 + * + * + * + * + * + * + * + * + *,
.pod H3 + * + * + * + * + * + * + * + * + * + * { margin-left: 100px;
}
[etc...]

Now, this works, but, a few problems come to mind immediately:
-The CSS is butt-ugly.
-It boosts the size of my resulting document considerably.
-Any more than 10 paragraphs under one heading, and the 11th will drop
back to the left margin.

Is there a better way to do this, ideally not involving an enclosing
element (which will be hard for me to generate)? Any help is most
appreciated!

Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sg********@hotmail.com wrote:
Grouping everything in a DIV isn't an option for me, because I'm not
the one generating the HTML (It's being done by a POD to HTML
converter: http://search.cpan.org/dist/Pod-HtmlEasy/).


Change the Perl script so that it wraps groups in a div.

--
Spartanicus
Nov 24 '05 #2

P: n/a
OK, I guess that's the "right" way to do it, and I was able to without
modifying the original source. Here's what I did, for reference by
Perl/Pod::HtmlEasy users:

#Create the Pod::HtmlEasy object...
my $podhtml = Pod::HtmlEasy->new(
#[snip]
#Revise the handler for =head2.
on_head2 => sub {
my ($this, $txt, $a_name) = @_;
my $html = '';
my $level = 2;
$html .= "</div>\n\n\n" if $this->{HEADING_LEVEL};
$html .= "<div class='h$level'>\n";
$this->{HEADING_LEVEL} = $level;
$html .= "<a name='$a_name'></a><h$level>$txt</h$level>\n\n";
},
#[Similar subroutine reference for on_head3]
);

That wraps the heading and subsequent items in a "<div
class='h2'>...</div>". Then I can do this in my stylesheet:

.h2 { margin-left: 50px; }
.h3 { margin-left: 100px; }
/*etc.*/

Works like a charm, even in IE.

The path I was on lead to madness; so thanks for the guidance.

Nov 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.