Home  >  Article  >  Web Front-end  >  How to insert style sheet in css

How to insert style sheet in css

(*-*)浩
(*-*)浩Original
2019-11-26 16:05:162407browse

How to insert style sheet in css

How to insert a style sheet

When a style sheet is read, the browser will format the HTML document according to it. There are three ways to insert a style sheet:

External style sheet (Recommended learning: CSS Getting Started Tutorial)

When the style needs to be applied When working with many pages, an external style sheet would be ideal. With external style sheets, you can change the look of your entire site by changing one file. Each page links to the style sheet using the 2cdf5bf648cf2f33323966d7f58a7f3f tag. 2cdf5bf648cf2f33323966d7f58a7f3f tag in the head (of the document):

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

The browser will read the style declaration from the file mystyle.css and format the document according to it.

External style sheets can be edited in any text editor. The file cannot contain any html tags. Style sheets should be saved with a .css extension. Here is an example of a stylesheet file:

hr {color: sienna;}
p {margin-left: 20px;}
body {background-image: url("images/back40.gif");}

Do not leave spaces between attribute values ​​and units. If you use "margin-left: 20 px" instead of "margin-left: 20px" it will only work in IE 6, but not in Mozilla/Firefox or Netscape.

Internal style sheets

When a single document requires special styling, an internal style sheet should be used. You can define an internal style sheet in the head of the document using the c9ccee2e6ea535a969eb3f532ad9fe89 tag, like this:

<head>
<style type="text/css">
  hr {color: sienna;}
  p {margin-left: 20px;}
  body {background-image: url("images/back40.gif");}
</style>
</head>

Inline styles

Because you want to mix presentation with content Together, inline styles lose many of the advantages of style sheets. Use this approach with caution, for example when the style only needs to be applied once to an element.

To use inline styles, you need to use the style attribute within the relevant tag. The Style property can contain any CSS property. This example shows how to change the color and left margin of a paragraph:

<p style="color: sienna; margin-left: 20px">
This is a paragraph
</p>

The above is the detailed content of How to insert style sheet in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn