twitter-bootstrap 引导 CDN 未加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23357102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap CDN Not Loading
提问by Incpetor
A simple yet annoying error.. I can't load the Bootstrap css using the cdn Here is the simple code
一个简单但令人讨厌的错误..我无法使用 cdn 加载 Bootstrap css 这是简单的代码
<html>
<head>
<title>Header template</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</head>
<body>
<button class="btn btn-default">Hello World</button>
</body>
</html>
回答by David De Sloovere
Two things might cause this:
有两件事可能会导致这种情况:
The obvious one is that you should remove the spaces in the first link (looks like you already edited that)
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">How are you viewing this file? If it is not served via a webserver (and thus over http of https) then the protocol-less links won't work. Does your browser say
file:///etc in the address bar? Then addhttp://in front of//netdna.bootstrapcdn.com
显而易见的是,您应该删除第一个链接中的空格(看起来您已经编辑过了)
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">您如何查看此文件?如果它不是通过网络服务器(因此通过 https 的 http)提供的,那么无协议链接将不起作用。您的浏览器是否
file:///在地址栏中显示等?然后http://在前面加上//netdna.bootstrapcdn.com
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
回答by Muhammad Ali Bala
Add the the Href with HTTP request. Use this may help you and solve your problem
添加带有 HTTP 请求的 Href。使用它可以帮助您并解决您的问题
<html>
<head>
<title>Header template</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</head>
<body>
<button class="btn btn-default">Hello World</button>
</body>
</html>
回答by Muhammad Ali Bala
The inclusion of the “http:” or “https:” part is partly just a matter of tradition, partly a matter of actually specifying the protocol. If it is defaulted, the protocol of the current page is used; e.g., //www.example.com becomes http://www.example.comor https://www.example.comdepending on the URL of the referring page. If a web page is saved on a local disk and then opened from there, it has no protocol (just the file: pseudo-protocol), so URLs like //www.example.com won't work; so here's one reason for including the “http:” or “https:” part.
包含“http:”或“https:”部分只是传统问题,部分是实际指定协议的问题。如果默认,则使用当前页面的协议;例如,//www.example.com根据引用页面的 URL变为http://www.example.com或https://www.example.com。如果一个网页保存在本地磁盘上然后从那里打开,它没有协议(只有文件:伪协议),所以像 //www.example.com 这样的 URL 将不起作用;所以这是包含“http:”或“https:”部分的原因之一。
Omitting also the “//” part is a completely different issue altogether, turning the URL to a relative URL that will be interpreted as relative to the current base URL.
省略“//”部分是一个完全不同的问题,将 URL 转换为相对 URL,该 URL 将被解释为相对于当前基本 URL。
The reason why www.example.com works when typed or pasted on a browser's address line is that relative URLs would not make sense there (there is no base URL to relate to), so browser vendors decided to imply the “http://” prefix there.
www.example.com 在浏览器地址行中输入或粘贴时起作用的原因是相对 URL 在那里没有意义(没有与之相关的基本 URL),因此浏览器供应商决定暗示“http:// ”前缀。

