简体   繁体   English

如何从CSS代码中分离html代码

[英]How to separate html code from css code

我有一个包含html和css代码的文件。如何将某些文件中的html代码与其他文件中的css分开?

Yes. 是。 You can save the css in a .css file. 您可以将css保存在.css文件中。 Then in your HTML head tags, you can do <link rel='stylesheet' href='yourcssfile.css'> 然后在你的HTML头标签中,你可以做<link rel='stylesheet' href='yourcssfile.css'>

<html>
  <head>
    <link rel='stylesheet' type='text/css' href='yourcssfile.css'>
  </head>
  <body>
    <p>Test</p>
  </body>
</html>

In yourcssfile.css yourcssfile.css

p {
  color:red;
}

This will make the paragraph text red and your CSS is within a different file. 这将使段落文本变为红色,并且您的CSS位于不同的文件中。

Simply put the CSS code into a file.css and include it in your HTML file. 只需将CSS代码放入file.css并将其包含在HTML文件中即可。

<head>
<link rel="stylesheet" type="text/css" href="file.css">
</head>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM