Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access css file in laravel 8? [duplicate]

I have been trying to access it like this:

<!DOCTYPE html>
<html lang="en">
 <head>
     <meta charset="UTF-8">
     <title>Document</title>
     <link rel="stylesheet" href="{{ asset('css/app.css') }}">
 </head>
 <body>
    <div class="red">
        @yield('content')
    </div>  
 </body>
</html>

I put the background red in the css file but nothing is changing. Any help is appreciated

enter image description here


2 Answers

put it in public/css and use it like this:

<link rel="stylesheet" href="{{ asset('/css/app.css') }}">
like image 184
Areg Ghazaryan Avatar answered Sep 19 '25 02:09

Areg Ghazaryan


You need to install laravel mix. As it is added in the package.json in fresh installation of laravel, follow below steps:

  1. run npm install to install package that are added in package.json more
  2. add mix.css('resource/css/app.css', 'css'); to the webpack.mix.js file more
  3. run npm run dev to compile files that are addressed in webpack.mix.js more
  4. link to your app.css as {{ asset('css/app.css') }} in the desired blade file.

Notice: You need to run npm run dev after any changes that you make in the resource/css/app.css file. Or benefit from npm run watch which complies automatically after any changes.

Notice: Press ctrl+f5 to clear cache after every change or use cache busting

like image 30
BABAK ASHRAFI Avatar answered Sep 19 '25 03:09

BABAK ASHRAFI