簡體   English   中英

我的CSS沒有在php上加載

[英]My css is not loading on php

嘿,我在file.html中為網站做了一個布局,但是我將其更改為.php,但我沒有使CSS生效。

 Body { margin: 0px; background-color: rgba(230, 230, 230, 1); font-size: 100%; } header, footer { padding: 1em; color: white; background-color: black; clear: left; background-color: RGBA(66, 161, 244, 1); } header{ height:10%; } footer{ height:2%; text-align: center; } #Logo{ position: relative; width: 50%; background-color: black; display: inline-block; height:100%; } #Search{ float: right; position: relative; width: 20%; height: 50%; display: inline-block; margin: 0px; } .Search{ width: 80%; height: 100%; } .SearchButton{ float: right; width: 19%; height: 100%; } nav { float: left; max-width: 160px; margin: 0; padding: 1em; } nav ul { list-style-type: none; padding: 0; } nav ul a { text-decoration: none; } article { margin-left: 170px; border-left: 1px solid gray; padding: 1em; overflow: hidden; } 
 <html> <head> <title>Unnamed Project</title> <link rel="stylesheet" type="text/css" href="Forside.css"> <link rel="stylesheet" type="text/css" href="Standart.css"> <meta charset="utf-8"> </head> <body> <header> <img src="Icon.png" id="Logo" href="Forside.php"></img> <form action="Forside.php" id="search" method="post"> <input type="text" name="Parameters" class="Search"></input> <input type="submit" value="Søg" class="SearchButton"></input> </form> </header> <nav> <ul> <li><a>Katagorier</a></li> </ul> </nav> <article> <div id='Produkt2'> <div id='Navn'> $row[Navn] </div> <div id='Produktnr'> $row[AutoID] </div> <div id='Billedpris'> <div id='Billed'> <img src='Billeder/$row[Billed]'></img> </div> <div id='Pris'> <a class='pris'>$row[Pris],-</a> <div id='Kurv'> <form action='PutiKurv.php' method='post'> <input type='hidden' name='antal' value='1'> <input type='hidden' name='ProduktID' value='$row[AutoID]'> <input type='submit' value='Læg i kurv:'></input> </form> </div> </div> </div> <div id='Info'> $row[Info] <div id='mere'> <form action='$row[Hjemmeside]'> <input type='submit' value='Mere info'></input> </form> </div> </div> <hr> </div>" </article> <footer>Copyright &copy; W3Schools.com</footer> </body> </html> 

它應該看起來像這樣,但是當我加載CSS時不見了。 請幫忙

問題是一個緩存問題。 CSS在緩存方面可能有點奇怪,並且經典的CTRL + F5組合適用於圖像,但不適用於CSS。 處理CSS中緩存的更好方法是在單擊刷新符號時按住SHIFT

顯然,您可以在CSS引用的文件路徑中包含反斜杠,或附加一個版本號,例如: <link rel="stylesheet" type="text/css" href="style.css?v2 />

這個版本號本來就不意味着什么,但是對於表示CSS的更新很有用,重要的是瀏覽器會認為它是一個不同的文件(強制它重新加載CSS)。

您還可以通過在鏈接的CSS文件中添加時間戳,強制瀏覽器每次在PHP加載頁面時自動刷新CSS,例如:

<link rel="stylesheet" type="text/css" href="style.css?<?php echo date('l jS \of F Y h:i:s A'); ?>" />

請記住,CSS可能是“昂貴的”,因此一旦完成開發,您可能希望通過刪除生產環境中的時間戳來允許訪問者緩存:)

希望這可以幫助! :)

當用雙引號或heredoc指定字符串時,將在其中解析變量。

您正在使用單引號而不是雙引號。 如果要解析變量,請使用雙引號。

在這里: <form action='$row[Hjemmeside]'>這意味着變量解析不起作用。 更改為<form action="<?php echo $row[Hjemmeside]; ?>">

同樣在這里: <input type='hidden' name='ProduktID' value='$row[AutoID]'> 更改為: <input type='hidden' name='ProduktID' value="<?php echo $row[AutoID]; ?>">

在這里: <img src='Billeder/$row[Billed]'></img> 更改為: <img src="Billeder/<?php echo $row[Billed]; ?>"></img>

另外,您可以在Web瀏覽器中進入“開發人員”模式,並執行“清空緩存並重新加載”選項以加載新樣式文件。 考慮使用文件版本控制。 例如:

<link rel="stylesheet" type="text/css" href="Forside.css?v=1.1">
<link rel="stylesheet" type="text/css" href="Standart.css?v=1.1">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM