Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

how do i get this code to display all h1/h2 items on the same line without the (cr) after each line,
Im new, very new to this so plz be gental?

print header,

start_html(-title=>'Site Admin',
h1('our little uploader -'),
h2('Item Upload');

Result needs to be: OUR LITTLE UPLOADER - Item Upload

Title edit by tye

  • Comment on CGI.pm: Rendering H1 and H2 tags in the same line

Replies are listed 'Best First'.
Re: Layout
by davido (Cardinal) on Nov 13, 2003 at 16:39 UTC
    CGI.pm, by default, doesn't insert \n anywhere in its output. What you are seeing is not the result of CGI.pm inserting "crlf" into your CGI program's HTML output. You can run the script from the command line and verify that statement yourself.

    What you are seeing is the fact that most browsers automatically render "headlines" one per row. In other words, a <h1></h1> pair always (in most browsers) renders on its own line, even if it's only a few characters long, and a subsequent <h2></h2> pair will render on a subsequent line, again, even if it's only a few characters.

    This isn't a Perl issue. It's truly an HTML issue. And I mean that not to try to pawn a problem off somewhere else. Seriously, it's not a Perl issue. It's a misunderstanding of how HTML works. You can solve it by using <font size=....></font> tags instead of headline tags in situations where you wish to control font size instead of rendering a headline.


    Dave


    "If I had my life to live over again, I'd be a plumber." -- Albert Einstein
      Totally agree.

      However, there is a yucky way to get them on one line:

      <TABLE><TR><TD><H1>Hello</H1></TD><TD><H2>world!</H2></TD></TR></TABLE +>

      Hello

      world!

      I have no idea how you would do this with CGI.pm.

      And yes, I know this isn't XHTML compatible. XHTML compatible HTML shouldn't contain abominations like this ;-)

      I also would recommend against using it this way: there are other, better ways for controlling the size of your text in HTML.

      Liz

      I think setting the CSS attribute white-space: pre-wrap on the two header tags will do it. Not sure, though.

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      : () { :|:& };:

      Note: All code is untested, unless otherwise stated

        What's supposed to be the way to do this is display attribute:
        .inline { display: inline } <h1 class='inline'>First</h1><h2 class='inline'> - Second</h2>

        First

        - Second

        Well that's what supposed to work. --
        Clayton
      thing is here I've only just picked this up today and can make HTML tags work it just keeps croaking on me could you example me something?

      thanks
      alan.

Re: Layout
by matthewb (Curate) on Nov 13, 2003 at 17:11 UTC
    #!/usr/bin/perl -T use strict; use warnings FATAL => 'all'; use CGI; my $q = CGI->new; print $q->header, $q->start_html, $q->h1( { -style => 'display: inline; ' }, q[OUR LITTLE UPLOADER + - ] ), $q->h2( { -style => 'display: inline; ' }, q[Item Upload] ), $q->end_html; exit;

    MB