Home >Web Front-end >CSS Tutorial >Can css be written in html?

Can css be written in html?

藏色散人
藏色散人Original
2020-12-03 12:02:204764browse

css can be written in HTML. The writing methods are: 1. Write css in the style tag of the head tag; 2. Add the style attribute directly to the HTML code, and then define the css code in the attribute. .

Can css be written in html?

The operating environment of this tutorial: windows7 system, css3&&html5 version, Dell G3 computer.

Recommended: "css video tutorial" "HTML video tutorial"

How to write css in HTML:

1. Internal style sheet - write css in the style tag of the head tag

When a single file requires special styles, you can use the internal style sheet. You can define internal style sheets via the c9ccee2e6ea535a969eb3f532ad9fe89 tag in the head section.

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

c9ccee2e6ea535a969eb3f532ad9fe89 tag is used to define style information for HTML documents.

In style, you can specify how the HTML document is rendered in the browser.

The type attribute is required and defines the content of the style element. The only possible value is "text/css". The

style element is located in the head section.

2. Inline style - add the style attribute directly to the HTML code, and then define the css code in the attribute.

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

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

The above is the detailed content of Can css be 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