11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravelでページごとに個別のcssを反映させたい

Posted at

#やりたいこと
※私は初心者です

.blade.phpファイルでは親レイアウトに

layouts/親.blade.php
<!DOCUTYPE html>
<html lang='ja'>
<head>
  <!-- 省略 -->
</head>
  <body>
    @yield('content')
  </body>
<html>
子.blade.php
@extends('layouts.親')

@section('content')
中身
@endsection

という感じでhtmlを埋め込めた。

これのcssバージョンをやりたい。
#2つのやり方があるみたい

  1. 子blade内に記述するパターン

普通に親側のheadタグ内で

```と書き、  

```php:子.blade.php
@section('css')
<!-- ここにcssを記述 -->
@endsection

とするやり方。
2. cssファイルを読み込むパターン

layouts/親.blade.php
<!DOCUTYPE html>
<html lang='ja'>
<head>
  @stack('css')
</head>
子blade.php
@push('css')
    <link href="{{ asset('css/子.css') }}" rel="stylesheet">
@endpush

という感じで書く。

11
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?