Yii framework 2.0 add media print to css link

↘锁芯ラ 提交于 2019-12-11 00:23:59

问题


Working with Yii framework 2.0 I include a css file with the code below inside assets/AppAsset.php.

public $css = [
    'css/style.css',
];

When I inspect element on the web browser I see the following code in the header tag:

<link href="/locahost/mywebsite/css/style.css" rel="stylesheet">

I would like to add the print.css to the web page with media='print'. How could I add the attribute media='print' into the css link within Yii framework 2.0?


回答1:


There is a cssOptions attribute for the Assetsbundle, where you can define the media, but it will add all of your css file registered in that asset.

If you want to use it separately, you need to create a new asset for that.

Within the URL below you can find, how to make a custom asset and how to register it to your app (layout):

http://www.ramirezcobos.com/2013/12/28/adding-fontawesome-to-your-yii2-project-via-composer/




回答2:


You just have to use the $options Array of View::registerCssFile(), like this:

$this->registerCssFile('myfile.css', ['media' => 'print']);


来源:https://stackoverflow.com/questions/26452227/yii-framework-2-0-add-media-print-to-css-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!