Jump to content
MakeWebGames

Stumped ... need help


Recommended Posts

Posted

hiya i have never used class varables before untill my project the shadow realm, i want to make a CSS class for my game so i can add only the css i need to the page for example

$css->AddId('CSS ID', 'CSS HERE eg margin:0px;');
$css->AddClass('CSS CLASS ID', 'CSS HERE eg border:none;');

i thought about laying it out like this

class css {
var $csssheet;

function Show(){ // no problems with this!
echo '<style type="text/css">
<!--
'.$this->csssheet.'
-->
</style>
';
}

function AddId($id, $css) {
$var=' #'.$id.'{ '.$css.' }';
$this->csssheet .= $var; // this dosent work though
}

}

this is probley a realy nobby question and will probly LOL at my self when i see what i done wrong but my mind has just gone blank :S

Posted
<?php

class Css {
public $cssSheet;

public function show() {
	echo '<style>'.$this->cssSheet.'</style>';
}

public function addClass($name, $content) {
	$newClass = '.'.$name.' { '.$content.' }';
	$this->cssSheet .= $newClass;
}

public function addId($name, $content) {
	$newId = '#'.$name.' { '.$content.' }';
	$this->cssSheet .= $newId;
}
}

$css = new Css;
?>

EDIT: Didn't see your previous post :S

Posted

thanks anyway, i just have to figure how to get the CSS from the bottom of the page to the top as it will bug me it being there lol

edit:

public function addId($name, $content) {
       $newId = '#'.$name.' { '.$content.' }';
       $this->cssSheet .= $newClass;

should be

public function addId($name, $content) {
       $newId = '#'.$name.' { '.$content.' }';
       $this->cssSheet .= $newId;

i did mine diffrent to yours, plus i am going to do this with my JS files aswell, i just want to clean up my HTML files as atm on one site i have 21 JS files loading up and 3 CSS files :S

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...