2014-04-29 103 views
2

一個簡單但煩人的錯誤。我可以使用CDN 這裏無法加載引導CSS是簡單的代碼引導CDN不加載

  <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> 
+1

它沒有加載的標誌是什麼? (你有沒有用DOCTYPE聲明試過?)另外:你是如何查看這個頁面的?如果您使用的是本地'file://'URL,則可能會發現'// ...'協議相關的URL不起作用。 –

+0

你的網站目前的協議是什麼? 'http','https'或者你是否用'file'在本地加載 –

回答

7

兩件事情可能會導致這樣:

  • 最明顯的一個是,你應該刪除在第一個鏈接的空間(看上去你已經編輯了)

    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

  • 你怎麼看這個文件?如果沒有通過網絡服務器(並因此通過http的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>

+0

@thanks Deef ..我想這是對此..正確的解釋,因爲當我運行它使用本地服務器,我沒有添加** http:**。我現在將遵循這個規則的形式..謝謝 – Incpetor

+0

很好的答案。對我而言,明確聲明https://而不是僅僅//立即修復它。 – Jage

1

添加與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> 
+1

@thanks Muhammad解決了我的問題..但是我在cnd中沒有使用http並且它工作正常..你能告訴我根本原因這個? – Incpetor

+0

是的,我在這裏測試它,它沒有http的罰款,但有時你必須定義協議。 –

+0

但我建議它更好,如果你可以下載這些所有js和css文件到你的本地項目文件。它會幫助你在沒有互聯網連接的情況下工作。 –

1

的列入「HTTP:」或「https:」部分是部分只是一個傳統的事情,部分原因是實際指定的協議的問題。如果是默認的,則使用當前頁面的協議;例如//www.example.com取決於引薦頁面的URL,變成http://www.example.comhttps://www.example.com。如果一個網頁保存在本地磁盤上,然後從那裏打開,它沒有協議(只是文件:僞協議),所以URL //www.example.com等URL不起作用;所以這裏有一個包含「http:」或「https:」部分的原因。

忽略「//」部分也是一個完全不同的問題,將URL轉換爲相對URL,將相對於當前基本URL進行解釋。

www.example.com在打印或粘貼到瀏覽器的地址行時工作的原因是,相對URL在那裏沒有意義(沒有與基準URL關聯),因此瀏覽器供應商決定暗示「 http://「前綴。