Home > other >  CSS with ID attribute not working on LARAVEL 8
CSS with ID attribute not working on LARAVEL 8

Time:01-03

I have called my css like this <link href="{{ URL::asset('/assets/css/app.min.css') }}" id="app-style" rel="stylesheet" type="text/css" />

There is id on tag css. this css successfully called the directory if my url site no sub domain like laravel.test/example. but the css fails to call if my url site like laravel.test/example/example2..

If i remove that id.. it work on all sites. but i need that id because its making some feature like change light/dark mode layouts.

So id='app-style' is going to file app.js. In app.js there is s("#app-style").attr("href","assets/css/app-dark.min.css"). app-dark.min.css is failure to call..

It will be easy if i can use blade on javascript.

CodePudding user response:

I think you should use asset() helper function but I'm not sure:

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

CodePudding user response:

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.

  • Related