Wilko
Wilko

Reputation: 399

Perl CGI using span to style data

I'm a CGI/HTML/CSS newbie but not too bad with perl. I'm writing a little CGI script and need to know how to change the style for certain elements of data on a line of text. I have adopted the Object Oriented approach to using CGI.

I'm iterating through an array of data and want to change the style of the variables on each line to something different from that standard style. My output for each line will look something like:

server=$hostName  appHost=$appHost  port=$port   cache=$maxCache

At the moment, I'm just doing:

print $cgi->br("server=$hostName  appHost=$appHost  port=$port   cache=$maxCache");

I'd ideally like each of the variables to be say, bold red (or preferably, a style that I've created in my CCS style sheet). I'm thinking that perhaps I need to use the span element but i've tried and failed miserably

Many thanks & regards

John

Upvotes: 1

Views: 762

Answers (1)

Barmar
Barmar

Reputation: 780842

In your perl script, write:

print $cgi-br "server=<span class='myclass'>$hostName</span>  appHost=<span class='myclass'>$appHost</span>  port=<span class='myclass'>$port</span>   cache=<span class='myclass'>$maxCache</span><br><br>";

(notice that the <br><br> needs to be inside the string, not outside).

Then in your CSS file, put:

.myclass {
    color: red;
    font-weight: bold;
}

You link them together by having your perl script print the following in the <head> section of the HTML:

print $cgi-br "<link rel='stylesheet' href='URL of your CSS file'/>";

Upvotes: 2

Related Questions