回答編集履歴
4
「xxxx.com」を「example.com」に変更してみました。
answer
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
<link rel="stylesheet" href="css/style.css" type="text/css">
|
15
15
|
上記記述だと、例えば以下のように、indexとそのほかのページの階層が異なる場合、
|
16
16
|
CSSが読み込めないページが多数生じると考えられます。
|
17
|
-
- https://
|
17
|
+
- https://example.com/css/style.css
|
18
|
-
- https://
|
18
|
+
- https://example.com
|
19
|
-
- https://
|
19
|
+
- https://example.com/aaaa/ (style.cssを読み込めない)
|
20
|
-
- https://
|
20
|
+
- https://example.com/aaaa/1234 (style.cssを読み込めない)
|
3
修正
answer
CHANGED
@@ -11,8 +11,9 @@
|
|
11
11
|
[https://qiita.com/kotsuban-teikin/items/9b00d0faa0b7eaf70796](https://qiita.com/kotsuban-teikin/items/9b00d0faa0b7eaf70796)
|
12
12
|
|
13
13
|
---
|
14
|
+
<link rel="stylesheet" href="css/style.css" type="text/css">
|
14
|
-
|
15
|
+
上記記述だと、例えば以下のように、indexとそのほかのページの階層が異なる場合、
|
15
|
-
|
16
|
+
CSSが読み込めないページが多数生じると考えられます。
|
16
17
|
- https://xxxx.com/css/style.css
|
17
18
|
- https://xxxx.com
|
18
19
|
- https://xxxx.com/aaaa/ (style.cssを読み込めない)
|
2
修正、Laravel公式ドキュメントのURLを追記
answer
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
`<link rel="stylesheet" href="css/style.css" type="text/css">`
|
1
|
+
変更前: `<link rel="stylesheet" href="css/style.css" type="text/css">`
|
2
2
|
↓
|
3
|
-
`<link rel="stylesheet" href="/css/style.css" type="text/css">`
|
3
|
+
変更前1: `<link rel="stylesheet" href="/css/style.css" type="text/css">`
|
4
|
-
|
4
|
+
(相対パスではなく、絶対パスにするといかがでしょうか?)
|
5
5
|
|
6
|
+
変更前2: `<link rel="stylesheet" href="{{ asset('css/style.css') }}" type="text/css">`
|
6
|
-
|
7
|
+
(Laravelには「asset()」という関数が用意されているようです。)
|
7
8
|
|
8
|
-
`
|
9
|
+
`asset()`についての参考:
|
10
|
+
[https://readouble.com/laravel/7.x/ja/helpers.html?header=asset()](https://readouble.com/laravel/7.x/ja/helpers.html?header=asset())
|
9
11
|
[https://qiita.com/kotsuban-teikin/items/9b00d0faa0b7eaf70796](https://qiita.com/kotsuban-teikin/items/9b00d0faa0b7eaf70796)
|
10
12
|
|
11
13
|
---
|
1
追記
answer
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
`<link rel="stylesheet" href="css/style.css" type="text/css">`
|
2
2
|
↓
|
3
3
|
`<link rel="stylesheet" href="/css/style.css" type="text/css">`
|
4
|
+
`<link rel="stylesheet" href="{{ asset('css/style.css') }}" type="text/css">`←追記
|
4
5
|
|
5
6
|
相対パスではなく、絶対パスにするといかがでしょうか?
|
6
|
-
(Laravelの仕組みとしてドキュメントルートを示す変数的な何かがあったような気がしますが..)
|
7
7
|
|
8
|
+
`{{ asset('css/style.css') }}`についての参考:
|
9
|
+
[https://qiita.com/kotsuban-teikin/items/9b00d0faa0b7eaf70796](https://qiita.com/kotsuban-teikin/items/9b00d0faa0b7eaf70796)
|
10
|
+
|
8
11
|
---
|
9
12
|
現状だと例えば以下のように、indexとindex2のパスが異なる場合、
|
10
13
|
片方でしかCSSが読み込めないということが生じると考えます。
|
11
|
-
-
|
14
|
+
- https://xxxx.com/css/style.css
|
12
|
-
|
15
|
+
- https://xxxx.com
|
13
|
-
- index2.blade.php
|
14
|
-
|
16
|
+
- https://xxxx.com/aaaa/ (style.cssを読み込めない)
|
17
|
+
- https://xxxx.com/aaaa/1234 (style.cssを読み込めない)
|