Bootstrap Stylesheet not applied

核能气质少年 提交于 2019-12-24 11:44:13

问题


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)


回答1:


You forgot the point, you must go before the first slash in the address of the folder:

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



回答2:


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!




回答3:


you are missing file extension in in html

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


来源:https://stackoverflow.com/questions/53995715/bootstrap-stylesheet-not-applied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!