简体   繁体   English

带有 ID 属性的 CSS 不适用于 LARAVEL 8

[英]CSS with ID attribute not working on LARAVEL 8

I have called my css like this <link href="{{ URL::asset('/assets/css/app.min.css') }}" id="app-style" rel="stylesheet" type="text/css" />我已经像这样调用了我的 css <link href="{{ URL::asset('/assets/css/app.min.css') }}" id="app-style" rel="stylesheet" type="text/css" />

There is id on tag css.标签 css 上有id this css successfully called the directory if my url site no sub domain like laravel.test/example.如果我的 url 站点没有像 laravel.test/example 这样的子域,则此 css 成功调用了该目录。 but the css fails to call if my url site like laravel.test/example/example2..但是如果我的 url 站点(如 laravel.test/example/example2..

If i remove that id .. it work on all sites.如果我删除该id .. 它适用于所有网站。 but i need that id because its making some feature like change light/dark mode layouts.但我需要那个id ,因为它有一些功能,比如改变亮/暗模式布局。

So id='app-style' is going to file app.js .所以id='app-style'将归档app.js In app.js there is s("#app-style").attr("href","assets/css/app-dark.min.css") .app.js中有s("#app-style").attr("href","assets/css/app-dark.min.css") app-dark.min.css is failure to call.. app-dark.min.css调用失败..

It will be easy if i can use blade on javascript.如果我可以在 javascript 上使用刀片,那将很容易。

I think you should use asset() helper function but I'm not sure:我认为您应该使用 assets asset()助手 function 但我不确定:

<link href="{{ asset('./css/app.min.css')}}" rel="stylesheet">    

In your blade you can check if something is or not.在您的刀片中,您可以检查是否有东西。 The you can include a condition to make the switch.您可以包含进行切换的条件。 Something like that:像这样的东西:

@php
    $hasDarkMode = true;
    $link = $hasDarkMode ? 'app-dark.min.css' : 'app.min.css';
@endphp

<link href="{{ URL::asset('/assets/css/' . $link) }}" 
  rel="stylesheet" 
  type="text/css" />

But it probably makes the most sense to make the condition on the href attribute.但在 href 属性上设置条件可能最有意义。

I decided to answer my own question.我决定回答我自己的问题。 Because id='app-style' is going to file app.js and there is some code to call other css..因为id='app-style'将归档app.js并且有一些代码可以调用其他 css..

i just need to change my app.js from asset to app.blade.php on view and set it on main layout.我只需要在视图中将我的app.js从资产更改为app.blade.php并将其设置在主布局上。

now i can change directory structure from blade.现在我可以从刀片更改目录结构。 s("#app-style").attr("href","assets/css/app-dark.min.css") to s("#app-style").attr("href","{{ asset('assets/css/app-dark.min.css') }}") s("#app-style").attr("href","assets/css/app-dark.min.css")s("#app-style").attr("href","{{ asset('assets/css/app-dark.min.css') }}")

How to reduce javascript code in wordpress websites and link is Free article submission sites如何减少 wordpress 网站中的 javascript 代码和链接是免费文章提交网站

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM