Home  >  Article  >  Web Front-end  >  Is css written in html?

Is css written in html?

青灯夜游
青灯夜游Original
2020-11-23 15:21:284445browse

css can be written in html, or in a ".css" file, and linked to the HTML file using the link tag; the method of writing css in html: 1. Use the style attribute, in Write the css style in the HTML tag; 2. Define the css style through the style tag in the head section.

Is css written in html?

The operating environment of this tutorial: Windows 10 system, CSS3 version. This method is suitable for all brands of computers.

There are three ways to add CSS styles in HTML: inline styles, internal style sheets and external style sheets; inline styles and internal style sheets are all written in HTML.

Inline styles

When special styles need to be applied to individual elements, you can use inline styles. The way to use inline styles is to use the style attribute in the relevant tags. The style
attribute can contain any CSS property. The following example shows how to change the color and left margin of a paragraph.

The style attribute specifies the inline style of the element.

The style attribute will override any global style settings, such as those specified in the

Syntax:

<element style="style_definitions">
  • style_definitions: One or more CSS properties and values ​​separated by semicolons. (For example: style="color:blue;text-align:center")

Example: Using the style attribute in HTML documents

<!DOCTYPE HTML>
<html>
<head> 
<meta charset="utf-8"> 
</head>
<body>
<h1 style="color:blue;text-align:center">这是一个标题</h1>
<p style="color:green">这是一个段落。</p>
</body>
</html>

Internal style Table

When a single file requires special styling, you can use an internal style sheet. You can define internal style sheets via the

Example:

<head>
<style type="text/css">
body {background-color: red}
p {margin-left: 20px}
</style>
</head>

External style sheet

css External style sheet is to save the css style in a separate file and use it in the HTML page Tag link.

Example:

Is css written in html?

CSS external style sheet linked to HTML

<head>
<link rel =“stylesheet”type =“text / css”href =“common.css”>
</head>

For more programming-related knowledge, please visit: Programming learning! !

The above is the detailed content of Is css written in html?. 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