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

Host-sensitive style sheet

P: n/a
I have a pair of webservers (actually virtual hosts in the same apache).
They are mostly clones, but one is used to develop changes, so is the
test system.

Most of the pages are generated by CGI scripts, and on the test system
the header incorporates <BODY BGCOLOR=#FFD0D0generating a puce
background which warns people of the test environment.

I can easily change this to inline CSS, but I'd prefer to use an
external stylesheet. I could use different stylesheets for the test and
production systems (and probably will, so I can test the effects of
changes in the stylesheet itself) but I started to wonder if there were
any way within CSS of setting the background colour based on the host.

One great advantage of a stylesheet which is sensitive to the host is
that it would solve the problem of having static HTML pages which
changed their background colour based on which host was being used.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Sep 5 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Steve Swift wrote:
I have a pair of webservers (actually virtual hosts in the same apache).
They are mostly clones, but one is used to develop changes, so is the
test system.

Most of the pages are generated by CGI scripts, and on the test system
the header incorporates <BODY BGCOLOR=#FFD0D0generating a puce
background which warns people of the test environment.

I can easily change this to inline CSS, but I'd prefer to use an
external stylesheet. I could use different stylesheets for the test and
production systems (and probably will, so I can test the effects of
changes in the stylesheet itself) but I started to wonder if there were
any way within CSS of setting the background colour based on the host.
No. But you can create segregate the difference off into a separate pair
of files named, say, bodybg.css, one on the test server containing only

body { background-color: #ffd0d0; }

and one on the production server containing only

body { background-color: #ffffff; }

Then, in your main CSS file, remove the rule that sets the background
color, and include

@import "bodybg.css";

at the top.
Sep 5 '08 #2

P: n/a
Steve Swift wrote:
I have a pair of webservers (actually virtual hosts in the same apache).
They are mostly clones, but one is used to develop changes, so is the
test system.

Most of the pages are generated by CGI scripts, and on the test system
the header incorporates <BODY BGCOLOR=#FFD0D0generating a puce
background which warns people of the test environment.

I can easily change this to inline CSS, but I'd prefer to use an
external stylesheet. I could use different stylesheets for the test and
production systems (and probably will, so I can test the effects of
changes in the stylesheet itself) but I started to wonder if there were
any way within CSS of setting the background colour based on the host.

One great advantage of a stylesheet which is sensitive to the host is
that it would solve the problem of having static HTML pages which
changed their background colour based on which host was being used.
Perl:

use CGI;

sub localMode
{
$localServerName=shift;
if( $ENV{SERVER_NAME} eq !localServerName)
{
return(
style({-type=>'text/css'},'body { background-color: #ffd0d0; }')
);
}
else
{
return('');
}
}
PHP

function localMode($localServerName)
{
if($_SERVER['SERVER_NAME' == $localServerName)
{
return '<style type="text/css">body { background-color:
#ffd0d0;</style>';
}
else
return '';
}
}

Just place function AFTER the last STYLE link.
--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Sep 5 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.