简体   繁体   English

CSS样式表实现

[英]CSS style sheet implementation

I've downloaded a style sheet that I want to use for a personal HTML webpage of mine. 我已经下载了一个样式表,希望将其用于我的个人HTML网页。 Quick question about implementing said style sheet. 有关实现所述样式表的快速问题。 A screenshot of the folder is here: http://imgur.com/94m11mz 该文件夹的屏幕快照位于: http : //imgur.com/94m11mz

I know to have an external style sheet I need to use the link tag, something akin to: 我知道有一个外部样式表,我需要使用链接标签,类似于:

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

My questions are these: 我的问题是:

1) Would href= "name of the .css files?" 1)href =“” .css文件的名称吗?“ ie href="default.css" 即href =“ default.css”

2) I'm not sure what to do with 2 .css files. 2)我不确定该如何处理2个.css文件。 Do I link to both of them? 我是否链接到他们两个? Meaning do I have 2 link tags? 意思是我有2个链接标签? One going to default.css and one going to fonts.css? 一种进入default.css,另一种进入fonts.css? Such as: 如:

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

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

3) Do I need to include all of the folders/.css files in the same folder as my HTML document? 3)是否需要将所有folder / .css文件与HTML文档包含在同一文件夹中? Or can I move that to a different folder if I explicitly type out the location to in href="name of .css file here" thing? 或者,如果我明确输入位置“ .css文件在这里的名称”中的位置,可以将其移动到其他文件夹吗?

You can move them to your own folder, for example: 您可以将它们移动到自己的文件夹中,例如:

<link rel="stylesheet" href="css/fonts.css" type="text/css">
<link rel="stylesheet" href="css/default.css" type="text/css">

And yes you need one link tag per css file you want to include in your html file(s). 是的,每个要包含在HTML文件中的CSS文件都需要一个链接标记。

You will need two link tags as they are different files, the folder structure depends on how you think it is appropriate. 您将需要两个链接标记,因为它们是不同的文件,文件夹结构取决于您认为合适的方式。 Generally it is a relative path like '..css/yourstylesheet.css' 通常,它是一个相对路径,例如“ ..css / yourstylesheet.css”

href takes the virtual path. href使用虚拟路径。 thats like say you have css folder in your root directory and the css file present in that then href = "css{your css filename}". 就是说您在根目录中有一个css文件夹,并且其中存在一个css文件,然后href =“ css {您的css文件名}”。

Question 1: Would href= "name of the .css files?" 问题1: href =“” .css文件的名称吗?“ ie href="default.css" 即href =“ default.css”

Yes you should name css with .css extension 是的,您应该以.css扩展名命名css

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

Question 2: I'm not sure what to do with 2 .css files. 问题2:我不确定如何处理2个.css文件。 Do I link to both of them? 我是否链接到他们两个? Meaning do I have 2 link tags? 意思是我有2个链接标签? One going to default.css and one going to fonts.css? 一种进入default.css,另一种进入fonts.css?

Yes , you can use two link tags but keep in mind if you have same class or id name in the two stylesheet it will take the style of last stylesheet. 是的 ,您可以使用两个链接标记,但是请记住,如果两个样式表中的类或ID名称相同,它将采用最后一个样式表的样式。

For eg: 例如:

if you have <div class="sample"> hi </div> in your html and in your default.css if you have .sample{color:red;} and in your font.css you have .sample{color:blue} then the text "hi" will appear blue in color as you have linked font.css second. 如果您的html和default.css中具有<div class="sample"> hi </div> ,如果您具有.sample{color:red;}font.css中您具有.sample{color:blue}然后,当您第二次链接font.css时 ,文本"hi"将显示为蓝色

Question 3: Do I need to include all of the folders/.css files in the same folder as my HTML document? 问题3:是否需要将所有folder / .css文件包括在与HTML文档相同的文件夹中? Or can I move that to a different folder if I explicitly type out the location to in href="name of .css file here" thing? 或者,如果我明确输入位置“ .css文件在这里的名称”中的位置,可以将其移动到其他文件夹吗?

It is highly recommended to keep all .css extension files under a single folder. 强烈建议将所有.css extension文件保留在一个文件夹中。 so that you can search for the stylesheet easily if you have large sum of files in your site. 因此,如果您的站点中有大量​​文件,则可以轻松搜索样式表。

And you should link like wise the stylesheet if you have it in a separate folder. 如果您将样式表放在单独的文件夹中,则应该明智地链接样式表。

Folder Name: CSS File Name : Default.css 文件夹名称:CSS文件名称:Default.css

<link rel="stylesheet" href="CSS/Default.css" type="text/css">

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

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