Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / CSS / November 2005



Tip: Looking for answers? Try searching our database.

Indenting headings and adjacent siblings?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sgarfunkle@hotmail.com - 23 Nov 2005 20:59 GMT
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!
Spartanicus - 24 Nov 2005 11:27 GMT
>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.

Signature

Spartanicus

sgarfunkle@hotmail.com - 28 Nov 2005 17:38 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.