简体   繁体   中英

Bootstrap Stylesheet not applied

on some of my pages I have bootstrap included.

Now on one page, I have an alert included, styled by bootstrap.

It's defined as simple as that:

 $('#wrongPasswordDiv').html('<br/><div class="alert alert-danger" id="wrongPWAlert" role="alert">Falsches Passwort. Bitte erneut versuchen!</div>');

Also, before, Bootstrap css file is included:

<link rel="stylesheet" type="text/css" href="/bootstrapcss" />

bootstrapcss is routed to the correct css file.

In the network tab, you can see that loading bootstrap works fine:

屏幕截图

But also, you can see, that even though it's loading, no classes are applied.

Now if I change the including of bootstrap to a CDN, it is working and the classes are perfectly applied.

Now I have no idea, what the problem is, becaue as you can see, bootstrap is loading and in both cases, it's loading, but only when loading from the CDN, the styles are applied.

Any ideas why?

Edit: after trying, if I load the CSS through the direct link instead of over the router, it's working. In another file, the same line is working perfectly fine though, so the routing seems to work fine (which you can see on the fact, that the file is loaded as well)

您忘记了这一点,您必须在文件夹地址中的第一个斜杠之前进行操作:

 <link rel="stylesheet" type="text/css" href="./bootstrapcss" /> 

As suggested and answered in another thread by Kobi, this is the answer to the question:

Using this route:

$router->map('GET','/bootstrapcss','example.css','bootstrapcss'); And

then while matching:

$match = $router->match();


 if($match['name'] === 'bootstrapcss'){
    header("Content-Type: text/css");
    $fileName = $match['target'];
    echo file_get_contents($fileName);
    return; }

Complete answer is here .

Thank you for the help again!

您缺少html中的文件扩展名

 <link rel="stylesheet" type="text/css" href="/bootstrap.css" /> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM