I have added css on custom phtml file using:
<link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('css/banner.css')?>">
and placed the CSS file in folder: Magento_Theme/web/css
When I load page and view the page content source it shows the CSS path as:
<link rel="stylesheet" type="text/css" href="http://xyz/magento-2/pub/static/version1530249778/frontend/Magento/mytheme/en_US/css/banner.css">
But not created any file on pub/static folder. I have cleared the cache and run the upgrade command.
Thanks
 asked Jun 29, 2018 at 5:42
 
 
 
 Rahul Singh 
 
 1,6702 gold badges20 silver badges40 bronze badges
 
 1 Answer 1
If your css file in Magento_Theme folder then you should follow this code:
<link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('Magento_Theme::css/banner.css')?>">
I hope it will works.
 answered Jun 29, 2018 at 5:49
 
 
 
 Emipro Technologies Pvt. Ltd. 
 
 4,1232 gold badges31 silver badges65 bronze badges
 
 - 
 <?php echo $block->getViewFileUrl('css/banner.css')?> why it not created on path mytheme/en_US/css/ ?Rahul Singh– Rahul Singh2018年06月29日 06:13:08 +00:00Commented Jun 29, 2018 at 6:13
- 
 I want to create the css on path mytheme/en_US/css/Rahul Singh– Rahul Singh2018年06月29日 06:14:17 +00:00Commented Jun 29, 2018 at 6:14
- 
 Then you should write like this: <link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('css/banner.css')?>"> & your css file in app/design/frontend/Vendor_Name/Theme_Name/web/css/file_name.css. folder.Emipro Technologies Pvt. Ltd.– Emipro Technologies Pvt. Ltd.2018年06月29日 06:19:48 +00:00Commented Jun 29, 2018 at 6:19
- 
 After that you need to setup upgrade & deploy static content data.Emipro Technologies Pvt. Ltd.– Emipro Technologies Pvt. Ltd.2018年06月29日 06:21:41 +00:00Commented Jun 29, 2018 at 6:21
- 
 M2 very complex as compare to old magento, anyway thanksRahul Singh– Rahul Singh2018年06月29日 06:24:50 +00:00Commented Jun 29, 2018 at 6:24
default