gpt4 book ai didi

php - 如何在 AssetBundle - Yii2 中添加 "type=' text/css'"For CSS

转载 作者:可可西里 更新时间:2023-11-01 00:40:54 25 4
gpt4 key购买 nike

我正在以这种方式使用我的 AppAsset

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',
];
}

但是,当我按 Ctrl + U 查看源代码时,

我得到 <link href="/css/style.css" rel="stylesheet"> .但是,没有 type='text/css' .

如何添加type='text/css'我所有的 CSS?

最佳答案

@Moped 回答:

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

我们可以使用$cssOptions为 CSS 添加属性。

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

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

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

而且,@Quentin 太正确了:

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.

因为添加了$cssOptions之后,虽然链接看起来像<link type="text/css" href="/css/style.css" rel="stylesheet"> .但是,它对 CSS 没有任何影响。

关于php - 如何在 AssetBundle - Yii2 中添加 "type=' text/css'"For CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38158638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com