簡體   English   中英

用HTML鏈接CSS文件

[英]Linking CSS file with HTML

我有一個HTML,它將引用CSS文件中的樣式。 但看起來HTML文件無法找到CSS文件。 我嘗試使用簡單的背景色,但這似乎也不起作用。

VOD.HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<div>
<table>
<tr>
<td><b>All</b></td>
{% for item in VOD1 %}
<td>ID: {{ item[0] }} <br/> Title: {{ item[1] }}<br/>
<img src="{{ item[2] }}" alt="dummy.jpg"> </img>
</td>
{% endfor %}
</tr>
<tr>
<td><b>Catch Up</b></td>
{% for item in VOD2 %}
<td>ID: {{ item[0] }} <br/> Title: {{ item[1] }}<br/>
<img src="{{ item[2] }}" alt="dummy.jpg"> </img>
</td>
{% endfor %}
</tr>
</table>
</div>
</body>
</html>

我的CSS文件如下。

mystyle.css

<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: black;
}
.myStyle{
height: 50px;
width:50px;
}

td{
height: 100px;
width: 100px;
}

h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
</html>

有人可以幫我嗎? 我對此HTML和CSS文件沒有太多經驗。

您的CSS文件應包含CSS,僅包含CSS,僅包含CSS。 它不應是HTML文檔。

刪除所有內容,除了:

body {
background-color: black;
}
.myStyle{
height: 50px;
width:50px;
}

td{
height: 100px;
width: 100px;
}

h1 {
color: maroon;
margin-left: 40px;
}

您不必將下面的行放在CSS文件中,這是HTML(不是CSS語言)。

<!DOCTYPE html>
<html>
<head>
<style>

所以mystyle.css變成

body {
  background-color: black;
}

.myStyle{
  height: 50px;
  width:50px;
}

td{
  height: 100px;
  width: 100px;
}

h1 {
  color: maroon;
  margin-left: 40px;
}

CSS文件是一種特殊類型的文件,可以用作html的一種“插入”。 由於它不是.html文件,因此不需要html標記,而html標記實際上會使文件無法正常工作。 相反,只要放

body {
background-color: black;
}
.myStyle{
height: 50px;
width:50px;
}

td{
height: 100px;
width: 100px;
}

h1 {
color: maroon;
margin-left: 40px;
}

等等。在此處了解更多信息: http : //www.w3schools.com/css/css_howto.asp

暫無
暫無

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

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