Solutions for thinkphp css references not coming in: 1. Check the storage location of js, css, img and other files; 2. Modify the way to reference css to "".
The operating environment of this article: Windows 7 system, thinkphp v5.1 version, Dell G3 computer.
What should I do if the css reference of thinkphp does not come in?
thinkphp5 references external css and the js path is indeed correct. Why is there no response?
After working on it all morning, I found out the reason and share it with you. Let me explain it with a css example:
1. We As you know, the js, css, img and other files we write are placed in public/static.
Here is the specific location map:
The three codes are as shown in the figure: index.html index.php index.css
html
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> p{ color: red; } </style> <link rel="stylesheet" href="public/static/index.css"> </head> <body> <p>{$name}欢迎你</p> </body> </html>
php
<?php namespace app\index\controller; class Index { public function index() { return view('index',[ 'name'=>'帅哥', ]); } }
css
p{ background-color: #000088; }
is like this, I use the most common link, through the picture above, Everyone knows that there is no problem.
Then we visit the local browser, it looks like this
There is no blue background, indicating that the link is not used
Why? The path is not used correctly Ah?
Then I found out through research that first of all, the integration software I use is laragon. This is not the point. I will post the root directory I set to
which is public, and then my link. It is , it should be changed to , so it is successful.
As shown in the picture, there is a background color.
To sum up, the css is ineffective because of the wrong judgment of the root directory. I hope my explanation will be helpful to everyone.
Recommended learning: "The latest 10 thinkphp video tutorials"
The above is the detailed content of What should I do if thinkphp's css reference does not come in?. For more information, please follow other related articles on the PHP Chinese website!