简体   繁体   English

Bootstrap样式表未应用

[英]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: 此外,之前,还包括Bootstrap css文件:

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

bootstrapcss is routed to the correct css file. bootstrapcss被路由到正确的css文件。

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. 现在,如果我将bootstrap的包含内容更改为CDN,则它可以正常工作,并且可以完美地应用这些类。

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. 现在我不知道问题是什么,因为如您所见,引导程序正在加载,并且在两种情况下都正在加载,但是仅当从CDN加载时才应用样式。

Any ideas why? 有什么想法吗?

Edit: after trying, if I load the CSS through the direct link instead of over the router, it's working. 编辑:尝试后,如果我通过直接链接而不是通过路由器加载CSS,则可以正常工作。 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: 正如Kobi在另一个主题中提出并回答的那样,这是问题的答案:

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" /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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