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

How would I do the following using CGI.pm ?
<FONT FACE \=\"$fontface\" SIZE\=\"$fontsize\" COLOR\=\"$fontcolor\"> +$mesg </FONT>
I got this much so far...
print $q->p-style( -family=>'verdana', -color=>'yellow', -size=>'1'), "COUNT: 000$count"), $q->endhtml();
but it doesn't work and now im stuck ;\ I really want to see how it's done with CGI if you could spare the time to show me.

Replies are listed 'Best First'.
Re: font attributes with CGI.pm
by davorg (Chancellor) on Nov 12, 2001 at 15:42 UTC
    $q->font({-face=>$fontface, -size=>$fontsize, -color=>$fontcolor}, $mesg);
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

      what about using style sheets?

        If you're using stylesheets then I'd imagine you'd be very unlikely to use font tags :)

        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you don't talk about Perl club."

Re: font attributes with CGI.pm
by Trimbach (Curate) on Nov 12, 2001 at 18:35 UTC
    As always, RTFM is generally a good place to start. :-D Thus spake the docs for the beloved CGI.pm:

    LIMITED SUPPORT FOR CASCADING STYLE SHEETS

    CGI.pm has limited support for HTML3's cascading style sheets (css). To incorporate a stylesheet into your document, pass the start_html() method a -style parameter. The value of this parameter may be a scalar, in which case it is incorporated directly into a <STYLE> section, or it may be a hash reference. In the latter case you should provide the hash with one or more of -src or -code. -src points to a URL where an externally-defined stylesheet can be found. -code points to a scalar value to be incorporated into a <STYLE> section. Style definitions in -code override similarly-named ones in -src, hence the name "cascading."

    You may also specify the type of the stylesheet by adding the optional -type parameter to the hash pointed to by -style. If not specified, the style defaults to 'text/css'.

    To refer to a style within the body of your document, add the -class parameter to any HTML element:

    print h1({-class=>'Fancy'},'Welcome to the Party');
    Or define styles on the fly with the -style parameter:
    print h1({-style=>'Color: red;'},'Welcome to Hell');
    You may also use the new span() element to apply a style to a section of text:
    print span({-style=>'Color: red;'}, h1('Welcome to Hell'), "Where did that handbasket get to?" );
    Note that you must import the ":html3" definitions to have the span() method available. Here's a quick and dirty example of using CSS's. See the CSS specification at http://www.w3.org/pub/WWW/TR/Wd-css-1.html for more information.
    use CGI qw/:standard :html3/; #here's a stylesheet incorporated directly into the page $newStyle=<<END; <!-- P.Tip { margin-right: 50pt; margin-left: 50pt; color: red; } P.Alert { font-size: 30pt; font-family: sans-serif; color: red; } --> END print header(); print start_html( -title=>'CGI with Style', -style=>{-src=>'http://www.capricorn.com/ +style/st1.css', -code=>$newStyle} ); print h1('CGI with Style'), p({-class=>'Tip'}, "Better read the cascading style sheet spec before +playing with this!"), span({-style=>'color: magenta'}, "Look Mom, no hands!", p(), "Whooo wee!" ); print end_html;

    Gary Blackburn
    Trained Killer