问题
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