[英]Link HTML file with CSS file in Visual Studio
我是 Visual Studio 的初學者,我的 html 文件/代碼工作正常,但我的 css 文件不起作用。 在工作區中未檢測到我的問題。
我也嘗試這樣做,沒有任何反應:
<link href= "CSS\index.css" rel="stylesheet" type="text/css">
CSS 代碼:
style
h1 {
background-color: blue;
}
你應該在你的 html 中使用 h1 標簽來查看結果
確保 index.css 文件在 CSS 文件夾內,然后添加以下鏈接標簽。
<link rel="stylesheet" href="./CSS/index.css">
我也是新手,但我想我可以提供幫助。 你有兩個選擇,我知道。
第一個也是理想的選擇是引用一個單獨的 style.css 文件來與您的主要 html 頁面一起使用(例如:index.html 和 style.css)。
(index.html)
<!DOCTYPE html>
<html>
<head>
<title>yourwebsite.com</title>
<link rel="stylesheet" type="text/css"
href="style.css">
</head>
<body>
<img src="your.jpg" alt="Handsome Man" width="100"
height="100">
<h1><b>your name</b></h1>
<p>your tag line</p>
<a href="https://twitter.com/yourtwitter"</a>
</body>
</html>
(樣式.css)
body{
background-color: #f4f4f4;
color: #555555;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: normal;
/* Same as above */
/* font: normal 12px Arial, Helvetica, sans-serif; */
line-height: 1.6em;
}
h1{
color: #00ff00;
}
p{
color: rgb(0,0,255);
}
第二個也是最糟糕的選擇是將您的 css 包含在您的主 html 文件中。
(Copied from https://ryanstutorials.net/css-tutorial/css-
including.php)
<!doctype html>
<html>
<head>
<title>Embedded CSS example</title>
<meta name="description" content="A page with embedded css">
<meta name="keywords" content="html css embedded">
<style>
h1 {
text-decoration: underline;
color: #4583c2;
}
p {
padding-left: 20px;
font-size: 18px;
}
</style>
</head>
<body>
...
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.