I'm new to HTML/CSS and I want to have one of my HTML files use a CSS file. How can I do 开发者_StackOverflow社区it?
In the <head>
tag of your HTML document add a line that looks like this:
<link rel="stylesheet" type="text/css" href="/path/to/your/style.css" />
I suggest you start by going through the w3schools CSS Tutorial.
This will guide you to define your CSS styles, which is what comes immediately after adding the style sheet to your HTML.
You can specify external style sheets with the following attributes of the LINK element:
Set the value of href to the location of the style sheet file. The value of href is a URL.
Set the value of the type attribute to indicate the language of the linked (style sheet) resource. This allows the user agent to avoid downloading a style sheet for an unsupported style sheet language.
- Specify that the style sheet is persistent, preferred, or alternate:
- To make a style sheet persistent, set the rel attribute to "stylesheet" and don't set the title attribute.
- To make a style sheet preferred, set the rel attribute to "stylesheet" and name the style sheet with the title attribute.
- To specify an alternate style sheet, set the rel attribute to "alternate stylesheet" and name the style sheet with the title attribute.
In this example, we first specify a persistent style sheet located in the file mystyle.css:
<LINK href="path_to_css_file" rel="stylesheet" type="text/css">
精彩评论