Loading a random Cascading Styles Sheet
Moderator: General Moderators
Loading a random Cascading Styles Sheet
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.
I intend to create several color schemes. Each time a page loads, I want it to load one randomly.
Thanks for your time.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
make an array of CSS files (including paths) and use array_rand() to write one to your <link rel="stylesheet">
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
-
nickvd
- DevNet Resident
- Posts: 1027
- Joined: Thu Mar 10, 2005 5:27 pm
- Location: Southern Ontario
- Contact:
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?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" />';
Code: Select all
echo '<link href="' . $randomCssFile . '" rel="stylesheet" type="text/css" />';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.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Code: Select all
<link href="/some/stylesheet.css" rel="stylesheet" type="text/css" />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"
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.
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.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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.
Work through the w3schools tutorials and try stuff - you'll pick up what you're missing.
Argh.
Didn't quite work. Likely to be a mistake on my part.
Here's my code.
index.php
header.php
black.css
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.
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>
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!';
?>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:
Code: Select all
<?php
echo 'Roar.';
?>
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.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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?
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?