skip to Main Content

Hey i’m using laravel 9 here and im using the SB ADMIN template from bootstrap , i’m making the template as a component <x-dashboard >...</x-dashboard> and i’m passing children inside it ! but i want the children to have it’s own css ( not the bootstrap one ) which is in my app.css file i added the head just so i can link the css file to the blade file but still doesn’t work any solutions ?

seeProscpect.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="stylesheet" href="{{ asset('../css/app.css') }}">
</head>
<body>
<x-dashboard >
    <h3 class="changeColor">TRYING CSS</h3>
</x-dashboard>
</body>
</html>

app.css


.changeColor {
   color: green;
}

2

Answers


  1. You have to use @pushonce for this purpose.

    @pushonce('styles')
      <link href="{{ mix('css/tile.css') }}" rel="stylesheet">
    @endpush
    
    Login or Signup to reply.
  2. Inside your <head> after all other CSS script put @stack('css')

    Ex:

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

    Then from your children blade, add @push or @pushonce
    Ex:

    @push('css')
    <link rel="stylesheet" href="{{asset('assets/css/blade_style.css')}}" />
    <style>
      .body {
         background: #000 !important;
      }
    </style>
    @endpush
    
    @section
    <h1>Children Blade Content</h1>
    @endsection
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search