Im trying to change the font color of a text which has already been set to white by default but no changes show. How can I get this to work for replacing default theme CSS?

CommentFileSizeAuthor
#8 css injector idea.png64.64 KBbrandonc503

Comments

zazinteractive’s picture

add !important at the end. Such as

margin-left: 10px !important;

honza pobořil’s picture

Title: Ability to override default CSS? » Ability to set weight of CSS file?

Its not clean solution. It could be better to allow set weights of inherited files.

zazinteractive’s picture

How would that work in code though?

Vayira’s picture

putting !important is not enough to overide the theme css. It would be useful have the option of applying the css rules after the theme css.

zazinteractive’s picture

Why wouldn't it override the theme css? Well, unless it is using !important as well.

merzikain’s picture

This may help someone else looking to do something similar, though this module is not necessary for it to work.

I have a style sheet aggregator script that someone else created and I modified.

function aggregate_stylesheets($args = array()){
	$oldstyles = $args['styles'];
	if(!isset($args['raw'])){
		global $mycatch_media_all; // globals are needed to handle the preg-results outside the replacement-routine
		global $mycatch_media_screen;
		global $mycatch_media_print;
		global $mycatch_media_rest;
		$mystyles = $mycatch_media_all = $mycatch_media_rest = ""; //reset of used vars
		
		function _mycatch_css_f ($match) {  // the callback-function for the preg-replacement-routine
			global $mycatch_not_rest;
			global $mycatch_media_all;
			global $mycatch_media_screen;
			global $mycatch_media_print;
				if(strpos($match[2],'modules') === FALSE){
					$weight = 100000;
				}else{
					$weight = NULL;
					$parts = explode('/',$match[2]);
					for($i = sizeof($parts); $weight == NULL && $i > 0; $i--){
						$q = db_query("SELECT * FROM {system} WHERE type = 'module' AND name = '%s'",$parts[$i]);
						if(db_affected_rows($q)){
							$info = db_fetch_array($q);
							$weight = $info['weight'];
						}
					}
					if($weight == NULL) $weight = 0;
				}
				if ($match[1] == "all") { $mycatch_media_all[$weight] .= '@import "'."$match[2]".'.css";'. "\n"; }
				else if($match[1] == "screen") { $mycatch_media_screen[$weight] .= '@import "'."$match[2]".'.css";'. "\n"; }
				else if($match[1] == "print") { $mycatch_media_print[$weight] .= '@import "'."$match[2]".'.css";'. "\n"; }
				else { $mycatch_media_rest[$weight] .= '<style type="text/css" media="'."$match[1]".'">@import "'."$match[2]".'.css";</style>' . "\n"; }
			return ''; // return nothing for replacement
		}
		
		$oldstyles = preg_replace_callback('#<link type="text/css" rel="stylesheet" media="(.*?)" href="(.*?)\.css(.*?)/>\n#','_mycatch_css_f', $oldstyles ); // the preg-replacement-routine. "#" seems to be needed for cutting "<" an ">" (found on php.net).
		
			ksort($mycatch_media_all);
			ksort($mycatch_media_screen);
			ksort($mycatch_media_print);
			ksort($mycatch_media_rest);
			$mycatch_media_all = implode('',$mycatch_media_all);
			$mycatch_media_screen = implode('',$mycatch_media_screen);
			$mycatch_media_print = implode('',$mycatch_media_print);
			$mycatch_media_rest = implode('',$mycatch_media_rest);
		$mystyles .= '<style type="text/css" media="all">' . "\n".$mycatch_media_all.'</style>'."\n";
		$mystyles .= '<style type="text/css" media="screen">' . "\n".$mycatch_media_screen.'</style>'."\n";
		$mystyles .= '<style type="text/css" media="print">' . "\n".$mycatch_media_print.'</style>'."\n";
		$mystyles .= $mycatch_media_rest . $oldstyles;
		
		return $mystyles;
	}else{
		return $args['styles'];
	}
}

You can call this in your template file or in a phptemplate_preprocess_page() template.php function.

It will sort the style sheets into media types and then sort those by the weight of the module that they came from, giving preference to theme files.

It works great for my purposes. Feel free to use/modify it as you need.

brandonc503’s picture

Issue summary: View changes

*deleted as i cant remove account

brandonc503’s picture

StatusFileSize
new64.64 KB

*deleted as i cant remove account