3

I'm using My AppAsset Like This Way.

AppAsset.php

<?php
namespace app\assets;
use yii\web\AssetBundle;

class AppAsset extends AssetBundle
{
  public $basePath = '@webroot';
  public $baseUrl = '@web';
  public $css = [
    'css/style.css',
  ];
  public $js = [
    'js/myscript.js',

  ];

  public $depends = [
    'yii\web\YiiAsset',
    'yii\bootstrap\BootstrapAsset',
    'yii\web\JqueryAsset',
  ];
}

But, when I press Ctrl + U to see source code,

I get <link href="/css/style.css" rel="stylesheet">. But, no type='text/css'.

How to add type='text/css' for all of my CSS?

5
  • Why do you want to? That's the default for links with rel=stylesheet. Commented Jul 2, 2016 at 9:35
  • Hi @Quentin : rel and type is 2 different properties for <link>. And, I'm getting rel by default. Then, why don't I get type property. Because, few design issues are there. Which HTML developer told me because of not having type. Commented Jul 2, 2016 at 9:39
  • 3
    I know the are different. The point is that the type attribute is optional, and if you omit it and specify rel=stylesheet then browsers will default to text/css. Your HTML developer is wrong. Adding a type attribute won't make any difference. Commented Jul 2, 2016 at 9:41
  • 3
    what about $cssOptions = array('type'=>'text/css'); .. never used Yii, but it can be found on their Docs Commented Jul 2, 2016 at 9:43
  • @moped : Thanks :) Commented Jul 2, 2016 at 9:56

2 Answers 2

5

@Moped Answered It :

what about $cssOptions = array('type'=>'text/css'); .. never used Yii, but it can be found on their Docs

We can use $cssOptions to add property for CSS.

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

public $cssOptions = ['type'=>'text/css'];  

public $js = [
   'js/myscript.js',    
];

And, @Quentin is too correct:

The point is that the type attribute is optional, and if you omit it and specify rel=stylesheet then browsers will default to text/css. Adding a type attribute won't make any difference.

Because after adding $cssOptions, though link look like <link type="text/css" href="/css/style.css" rel="stylesheet">. But, it didn't made any difference to CSS.

Sign up to request clarification or add additional context in comments.

1 Comment

you're welcome, this is what I call 55+ points out of the window :D
0

This is how you can set options for a specific style:

public $css = [
    ['css/style.css', 'rel' => 'text/css'],
    ['css/style-2.css', 'rel' => '...'],
    'css/style-3.css',
];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.