Home Web Front-end HTML Tutorial Cascading style sheet CSS_html/css_WEB-ITnose

Cascading style sheet CSS_html/css_WEB-ITnose

Jun 24, 2016 am 11:52 AM

??

1. What is a cascading style sheet
css is to control the display of styles on web pages
2. Several ways to set css
inline Style sheet (Inline styles)
Set the style attribute of the tag
When using inline style sheets, the html4.01 standard recommends adding the following

Reason: The new version of html can not only use css but also use other methods, such as using text/sml to control the display effect of xml in html

Disadvantages: It needs to be set in each tag. Inline style sheets will work on all media
Embedded style sheets
Defined in the tag

                      < style>
The basic format of each style rule defined in the tag pair is as follows:
selector{property:value;property:value;...}
selector : When defining a style rule, the web page elements affected by this rule must be specified.
The web page element defined in a rule is the selector (selector), that is, the web page element affected by the style rule is selected
property: Specify the style names to be modified, i.e. css attributes, such as color
Value: The value assigned to property, i.e. css attribute value

Disadvantage:
must be written in every page
External style sheet

type and media attributes It is optional

Save the external style sheet in the buffer to speed up the loading of the web page

Advantages: It can make the web page slimmer

Input style sheet
You can use css The @import statement imports an external style sheet (css file) into two external css files. The style rule definition statements in the imported css

file become part of the imported css file.

You can also use the @import statement to import a css file into the tag of the web page. The
style rule definition statement in the imported css file becomes tag pair.

An example statement using the @import declaration is as follows:

3. Selector of style rules
HTML selector: html tag
Class selector:
To divide each web page element created by an html tag into several categories, you need to divide the class of this HTML tag Properties are set to different values
                                                           class="normal"> paragraph1


In the style sheet, you can define style rules for each category of an HTML tag

In a style sheet, it can be defined for all HTML tags of a category Style rules:


Blue title

Blue paragraph



ID selector

The ID attribute is used to define a specific HTML element in a web page file Only one element can use a certain ID attribute value

ID Selector is to select HTML elements with a certain ID attribute value for the style rule definition statement.

terst

In the style sheet, the HTML element style rule definition statement with the id value yellowone is as follows:



Associative selector

Associative selector refers to two or more single selectors separated by spaces The string composed of

For example: P EM {background: yellow}
where "P EM" is the associated selector, which represents the emphasized text in the paragraph ( tag pair The background of the content) is yellow,
while the emphasized text appearing elsewhere will not be affected

The selection right of the style rules defined by the associated selector has a higher priority than the style rules defined by the single selector. , even if the following style rule is defined in the back part of
P EM{background: yellow}: EM{background: green}
However, the emphasized text defined in the paragraph tag

still uses a yellow background

Combining selectors

In order to reduce repeated declarations in style sheets, you can combine several selectors in one style rule definition statement, and separate each selector with a comma (,)

For example: H1 ,H2, H3, H4, H5, H6, td{color:red}

Pseudo-element selector

Pseudo-element selector refers to the various states of the same HTML element and its included A way of defining part of the content.

For example, for the normal state of the hyperlink tag , the visited state, the selected state, the state when the cursor moves to the hyperlink text,
can be used for the first letter and first line of the paragraph. Pseudo element selector to define.
Style rule definition for using pseudo-elements as selectors:
HTML: Pseudo-element {attribute: value}
Commonly used pseudo-elements:
A:active The state when a hyperlink is selected
A :hover The cursor moves to the state of the hyperlink
A:link The normal state of the hyperlink (before any action)
A:visited The visited hyperlink state
P:first-line in the paragraph First line of text
P:first-letter The first letter in the paragraph
Class selector format used with pseudo-element:
HTML element. Class name: pseudo-element {attribute: value}

4. Comments on style rules

There are many style attributes in css, which can be roughly divided into the following categories:

Font, background, text, position, layout, edge, list, others

5. Detailed explanation of style attributes

Filter(css filter)

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

See all articles