<Proposal and Ask> Add custom.css for 2.0.1

Yii2.

yii2/apps/basic/web/css/

Hi all…

May be some situation we want add/change minor additional css rule.

But we do not want change any site.css content.

Then we can use custom.css.

Hopeful this custom.css can available together site.css in yii2 2.0.1.

So, we have:

  • yii2/apps/basic/web/css/site.css

  • yii2/apps/basic/web/css/custom.css

Now, for yii2 2.0.0, how can we register custom.css like site.css,

so it run latest loaded, can run everywhere just like site.css?

Thank you :)

got it.

if we want add new css to our site, go to app/basic/assets and open AppAsset.php.

and add custom.css after ‘css/site.css’.




<?php

/**

 * @link http://www.yiiframework.com/

 * @copyright Copyright (c) 2008 Yii Software LLC

 * @license http://www.yiiframework.com/license/

 */


namespace app\assets;


use yii\web\AssetBundle;


/**

 * @author Qiang Xue <qiang.xue@gmail.com>

 * @since 2.0

 */

class AppAsset extends AssetBundle

{

    public $basePath = '@webroot';

    public $baseUrl = '@web';

    public $css = [

        'css/site.css',

        'css/custom.css',

    ];

    public $js = [

    ];

    public $depends = [

        'yii\web\YiiAsset',

        'yii\bootstrap\BootstrapAsset',

    ];




thank you yii2 :)

I just needed some css for printing, I could set this in only one view:

$this->registerCss("

  

@page

{

 size:A4;

 margin: 0;

}

@media print{

   #print-btn

   {

      

     display: none;

     visibility: none;

   }

}

   ");

You can also register a LinkTag, but i couldnt make it work, there was something in the route, I hope it could be useful for someone else:

 $assets = '../css';
$baseUrl = Yii::$app ->assetManager->publish($assets); 

    ob_start();

    var_dump($baseUrl);

    Yii::debug(ob_get_clean(),"set css"); 

     $this->registerCss("uwu",["href"=>$assets . '/printStyle.css']);

    $this->registerLinkTag(["href"=> $assets . '/printStyle.css',"rel"=>"stylesheet"])