Page 1 of 2
Loading a random Cascading Styles Sheet
Posted: Sat Feb 10, 2007 7:10 pm
by nimmØ2
I'm not sure if I'm using the right terminology, nor whether I'm using it correctly or not.
I intend to create several color schemes. Each time a page loads, I want it to load one randomly.
Thanks for your time.
Posted: Sat Feb 10, 2007 9:15 pm
by Kieran Huggins
make an array of CSS files (including paths) and use
array_rand() to write one to your <link rel="stylesheet">
Posted: Sat Feb 10, 2007 9:52 pm
by superdezign
Beware: Changing colors like that is something that we usually avoid in website design from page to page unless the user is given a choice. Just know that by doing what you're doing, try not to make the colors too different (or too bright... That'd just hurt the users eyes!)
Posted: Sun Feb 11, 2007 12:18 am
by nimmØ2
haha, thanks.
Mostly I'm just playing with things.
But I'll keep that in mind.
Could you possibly post snippets of code?
I'm very inexperienced, but don't want others writing all the code for me.
I want to learn.
Posted: Sun Feb 11, 2007 12:24 am
by nickvd
Code: Select all
//untested
$cssFiles = array('fileone.css','filetwo.css','filethree.css');
$randomCssFile = array_rand($cssFiles);
echo '<link href="' . $randomCssFile . '" rel="stylesheet" type="text/css" />';
Posted: Sun Feb 11, 2007 4:17 am
by nimmØ2
nickvd wrote:Code: Select all
//untested
$cssFiles = array('fileone.css','filetwo.css','filethree.css');
$randomCssFile = array_rand($cssFiles);
echo '<link href="' . $randomCssFile . '" rel="stylesheet" type="text/css" />';
Ah, now could someone please explain how this line of code works?
Code: Select all
echo '<link href="' . $randomCssFile . '" rel="stylesheet" type="text/css" />';
Is that echo I see? I'm unsure of what is to be displayed.
I've got the link, the concatination, and the varialbe, I think the 'type="text/css" is html, but am not sure how it works.
I also have no clue where rel="stylesheet" comes into play.
Thanks for the response, nick.
Posted: Sun Feb 11, 2007 4:32 am
by Kieran Huggins
Code: Select all
<link href="/some/stylesheet.css" rel="stylesheet" type="text/css" />
That's the html to include a stylesheet.
The echo and the variable are PHP.
Check out
http://w3schools.com for an intro to html and/or css.
Also, your signature could be summed up as: "I ramble"

Posted: Sun Feb 11, 2007 5:39 am
by louie35
Kieran Huggins wrote:
Also, your signature could be summed up as: "I ramble"

I like that.
Posted: Sun Feb 11, 2007 6:18 am
by nimmØ2
So an external style sheet is loaded into my document.
I think I made the mistake of learning the little html I know through Frontpage.
While Frontpage made mediocre websites suitable for Middle School Project or High School Assignments,
it's flexibility is obviously limited, and I think I missed out on getting a solid foundation on html.
I'm reading up on how to create and use Cascading Style Sheets now.
What software would you guys recommend for using them within a website?
Dreamweaver?
Or Notepad. I'm not sure if this is something to be hand-coded or not.
Thanks again.
Posted: Sun Feb 11, 2007 6:39 am
by Weirdan
Choose any editor with syntax highlighting - and you will be fine for the most part.
Posted: Sun Feb 11, 2007 8:18 am
by superdezign
When it comes to stylesheets, you could use Notepad and be as well off as anyone else. As long as you know the properties, and are aware of how easy it is to add an extra semicolon or bracket by accident, you'll be fine.
Posted: Sun Feb 11, 2007 3:37 pm
by Kieran Huggins
There's a whole thread on php/html/css editors somewhere, I use
EditPlus.
Work through the w3schools tutorials and try stuff - you'll pick up what you're missing.
Posted: Mon Feb 12, 2007 6:07 am
by nimmØ2
mm.
Wish me luck.

Argh.
Posted: Mon Feb 26, 2007 7:14 am
by nimmØ2
Didn't quite work. Likely to be a mistake on my part.
Here's my code.
index.php
Code: Select all
<html>
<header>
<title>Here comes the date again.</title>
<?php
include("header.php");
?>
</header>
<body>
<h1>Roar!</h1><br>
<h2>Roar!</h2><br>
<p>Roar!</p><br>
<l>Roar!</l><br>
<kindaskinnytext>kindaskinnytext</kindaskinnytext><br>
<skinnytext>skinnytext</skinnytext><br>
<reallyskinnytext>reallyskinnytext</reallyskinnytext>
</body>
</html>
header.php
Code: Select all
<?php
$cssFiles =
//I'm not sure how to put quotation marks into a string, so I put the entire url instead of a relative one.
array('http://www.nimm02.com/workspace/css/black.css','http://www.nimm02.com/workspace/css/white.css','http://www.nimm02.com/workspace/css/grey.css');
$randomCssFile = array_rand($cssFiles);
echo '<link href="' . $randomCssFile . '" rel="stylesheet" type="text/css" />';
echo 'Hi!';
?>
black.css
Code: Select all
body {background-color: black}
kindaskinnytext {letter-spacing: -1px}
skinnytext {letter-spacing: -1.5px}
reallyskinnytext {letter-spacing: -2px}
h1 {color: gray}
h2 {color: darkgray}
p {color: White}
l {color: lightGray}
/* Both white.css and grey.css are very similar with different color values. */
After a bit of troubleshooting I tried using this as my header.php:
And found that it wasn't displaying even that.
I do know that my host supports php, as I've tested other things.
Help would be appreciated.
The output can be found at
http://www.nimm02.com/workspace/css/
Thank you kindly.
Posted: Mon Feb 26, 2007 9:35 am
by feyd
The output right now is showing different results than what the above PHP should be showing.
But there are a few things to note: There's no <header>, <l>, <kindaskinnytext>, <skinnytext>, or <reallyskinnytext> tags in the standards.
Your code appears to be confused as to what it's using. Are you using HTML 4, or XHTML?