How to specify priority of CSS files

Hello Everyone,

Is there a way I can specify priority of CSS files. Consider this scenario.

I have included a standard text.css file in my layout/main.php using clientScript->registerCssFile, but in one of my controller I want to include controller specific CSS file(posts.css). I include it in controller’s view files (where required). Now what happens is that my posts.css is included first and then my text.css which overwrites rules defined in posts.css.

Is there a way I can fix this?


I avoid to rely on priority of css.

When I have to overwrite some rule (for example in a form) I add a class to the div form and then rely on this class for override the rules.

This solves lot of conflicts

I have extended CClientScript to implement this requirement, as I use 960 framework and Yii includes it’s files after all other CSS files no matter where I register them.

May be this can help others.


class DX_ClientScript extends CClientScript



	public function renderHead(&$output)



		foreach($this->metaTags as $meta)


		foreach($this->linkTags as $link)


		/* changes by dx-sadaf */

		foreach($this->cssFiles as $k=>$file){



		/* end changes*/

		foreach($this->css as $css)






				foreach($this->scriptFiles[self::POS_HEAD] as $scriptFile)
















	public function registerCssFile($url,$media='',$index=null)



		if( !in_array(array('url' => $url, 'media'=> $media),$this->cssFiles))


			if (is_null($index)) {

				$this->cssFiles[] = array('url' => $url, 'media'=> $media);


				array_splice($this->cssFiles,$index,null, array(array('url' => $url, 'media'=> $media)) );





		return $this;


	public function isCssFileRegistered($url)


		if( empty($this->cssFiles) ) {

	        return false;


	    foreach ($this->cssFiles as $k=>$file_info){

	    	if ($file_info['url'] == $url) {

	    		return true;



	    return false;