我应该将CSS和Javascript代码放在HTML网页中? [英] Where should I put the CSS and Javascript code in an HTML webpage?
问题描述
在设计网页时,我应该在哪里放入以下代码?
While designing a webpage, where should I put the following code?
< link rel = stylesheet type =text / css href =css / layout.css>
我应该把它放在< head> / code>或者我应该把它放在
< body>
?
请澄清以下问题:
Should I put it in the <head>
or should I put it in the <body>
?
Please clarify the following questions:
- 如果我把它放在
- 如果我有两个CSS(或Javascript)文件,该怎么办?
推荐答案
在我看来,最好的做法是将CSS文件放在标题中
In my opinion the best practice is to place the CSS file in the header
<head>
<link rel="stylesheet" href="css/layout.css" type="text/css">
</head>
和关闭前的Javascript文件< / body>
标记
and the Javascript file before the closing </body>
tag
<script type="text/javascript" src="script.js"></script>
</body>
如果你有,像你说的两个CSS文件。浏览器将使用两者。如果有任何选择器,即。 .content {}
在两个CSS文件中相同,浏览器将使用第二个属性覆盖第一个的类似属性。如果这是有道理的。
Also if you have, like you said two CSS files. The browser would use both. If there were any selectors, ie. .content {}
that were the same in both CSS files the browser would overwrite the similar properties of the first one with the second one's properties. If that makes sense.
这篇关于我应该将CSS和Javascript代码放在HTML网页中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!