HTML5 and CSS3 basic tutorial version 8 study notes 7 ~ Chapter 10-ordinary people in the ordinary world chapter 7, CSS Constructor
CSS contains the attributes (font-size, color) that control the basic format, the position and float attributes that control the layout, and the print control elements that determine where visitors change pages when printing. CSS also has many dynamic attributes that control the display or disappearance of projects. They can be used to create lists and other interactive components.
Create style rules
Each rule in the style sheet has two parts: Selector and declaration block.
The selector determines which blocks are affected. It declares that a block is composed of one or more Attribute-value pairs and specifies what to do.
Add comments to style rules
/* Comment */, which can be a multi-row comment. It can be placed anywhere in the style sheet. It must appear in pairs and cannot be nested.
Understanding inheritance
Inheritance is a very important concept in CSS. The browser interprets HTML as a document tree. When CSS attributes are applied to an element, not only the element but also its branch element are affected.
For most attributes, you can use the inherit value to forcibly inherit
Inherited CSS attributes
Text:
Color: color, except for element
Direction: direction
Font: font
Font-family: font family
Font-size: font size
Font-style: Used to set italics
Font-variant: Used to set small uppercase letters
Font-weight: Used to set bold
Letter-spacing: letter spacing
Line-height: Row height
Text-align: used to set the Method
Text-indent: used to set the indent of the first line
Text-transform: used to modify the case sensitivity
Visibility: visibility
White-space: used to specify how to process Spaces
Word-spacing: word spacing
List:
List-style: list style
List-style-image: used to specify custom tags for the list
List-style-position: used to determine the position of the list tag
List-style-type: used to set the tag of the list
Table:
Border-collapse: used to control whether the border of adjacent cells in a table is merged into a single border
Border-spacing: used to specify the gap size between table borders
Caption-side: used to set the position of the table title
Empty-cells: Used to set whether to display empty cells in the table
Page settings:
Orphans: used to set the minimum number of lines to be retained at the bottom of the page when the element is paged internally.
Page-break-inside: used to set the paging mode inside the element.
Widows: used to set the minimum number of rows to be retained at the top of the page when a page is displayed inside the element.
Others:
Cursor: mouse pointer
Quotes: used to specify the quotation mark Style
Cascade: When rules conflict
When the rule definition does not conflict, multiple rules are combined and applied to the element together.
1. When the written rules conflict with the default browser rules, the written rules shall prevail.
2. conflicting rules are written. CSS uses the cascade principle to consider the particularity, order, and importance, so as to determine which rule should take effect in conflicting rules.
(1) Special
Special rules specify the degree to which the selector is specific. The more special the selector is, the stronger the rule. In case of conflict, rules with strong particularity are prioritized. The id selector is the most special.
Suggestion: Use the class selector in the style sheet to avoid using the ID selector. Reduces flexibility.
(2) Order
The priority for later appearances is high. Rules directly applied to HTML elements are considered to appear later than rules with the same characteristics in external style sheets or inserted at the top of HTML documents.
(3) Importance
A special rule can be declared to cover all the rules in the system. This rule is more important than all other rules. You can also add it at the end of a declaration! Important, for example, p {color: red! Important;} Not recommended
Attribute Value
1. inherit: indicates that the property value is the same as the value set by the corresponding parent element for this property. P {border: inherit} (before IE8, most attributes do not support inherit values)
2. predefined values. Most CSS attributes have predefined values available for use. For example, float can be set to left, right, or none.
3. Length and percentage. Em, px, pt, percentage. The length of an em is approximately equal to the font size of the corresponding element. (When em is used to set the font-size attribute, its value inherits the font size of the corresponding parent element)
4. Pure numbers. Only a few CSS attributes receive numbers without unit. The most common ones are line-height, z-index, and opacity.
5. URL
6. CSS color
7. RGB
8. hexadecimal number
9. More designated color methods provided by CSS3: RGBA, HSLA, and HSL
RGBA: An A representing alpha transparency is added based on RGB. All modern browsers are supported, not earlier than IE9. Format: color: rgb (127, 127), color: rgba (0.75)
HSL and HSLA
HSL: hue, saturation, and lightness ). Color Range: 0-360, saturation and brightness are percentages: 0-100%
Format: property: hsl (hue, saturation, lightness );
HSLA format: property: hsla (hue, saturation, lightness, alpha transparency)
Chapter 8 operational style sheets
Make sure that cssfiles are saved as files with. CSS extension and UTF-8 Encoding
External style sheets can be referenced through links or imported (via import). It is not recommended to import them, and the performance is poor.
Link to external style sheet
Syntax:
You can use multiple link elements to load multiple style sheets on the page. If there is a conflict, the rules of the subsequent files will prevail.
Create an embedded style sheet
In the head section.
Only when the style element appears after the link element, the style embedded in the style sheet will overwrite the style in the external style sheet.
Apply inline Style Sheets
Define the style attribute in HTML elements. Inline styles take precedence over all other styles, unless the conflicting styles are marked elsewhere! Important
Cascade and sequence of styles
The relationship between an embedded style sheet and any external style sheets connected to it depends on their relative position in HTML. If a conflict occurs, the occurrence order is later.
The Inline style has the highest priority. Once applied, all conflicting styles are overwritten.
Conflicting style order affects priority. An exception is to mark! The important style always has the highest priority. Try not to use important unless you have
Use a media-related style sheet
You can specify a style table for specific output only. For example, you can create a general style table with Features shared by print and screen versions, and then create a separate attribute for printing only and for display only. Media attributes are used in link or style elements. For example, media = "output" can be print, screen, or all (these are the most common ).
Chapter 9 defines Selector
Suggestion: Do not use the id selector whenever possible
An important goal of CSS writing is to make the selector as simple as possible and only keep necessary particularity.
Select elements by name
Type Selector
Select elements by class or ID
1. Select the elements to be formatted by class
Start with. (DOT) and enter className without spaces.
2. Select the elements to be formatted by ID
Start with # (well number) and enter idName without spaces
Unless it must be specific to the target element, it is recommended that you do not add element names in the id or class selector to reduce flexibility.
Comparison between class selector and ID Selector
We recommend that you use the class selector whenever possible.
The id selector introduces the following issues:
1. Reusable
2. Strong particularity. It is difficult to manage to cover the need to write rules with higher particularity
Select elements by context
1. Sub-selector:>
.architect > p{ color:red;}
This selector only selects the p element of the child element (not child element or child element) of the effecect class element.
2. CSS adjacent compatriot OPERATOR: +
H1 is adjacent to p, h1 is not adjacent to h2, and p is adjacent to h2.
.architect p+p{ color:red;}
3. Common compatriot OPERATOR :~
h1~h2{ color:red;}
Select the first or last child element
: First-child,: last-child. All are pseudo classes.
li:first-child{ color:red;}
The selected
1, Is not a child element of li, such as last-child.
Select the first letter or line of the element.
: First-letter,: first-line
Pseudo element: first-letter,: first-line,: before,: after
Pseudo class: first-child,: link,: hover
Select link elements by status
A: link: the appearance of a link that has never been activated or pointed to, and has not been activated or pointed.
A: visited: the appearance of the activated link of the visitor
A: focus: Make sure that the link is selected on the keyboard and is ready for activation.
A: hover: the link appearance when the cursor points to the link
A: active: the appearance of the activated Link
Select elements by attribute
| Selector |
Attribute Value |
| [Attribute] |
Matches the specified attribute, no matter what the value is |
| [Attribute = "value"] |
Exact match of specified attribute value |
| [Attribute ~ = "Value"] |
The attribute value is multiple words separated by spaces, one of which exactly matches the specified value. |
| [Attribute | = "value"] |
Value-hitting the attribute value |
| [Attribute ^ = "value"] |
The attribute value starts with value. value is a complete word or part of a word. |
| [Attribute $ = "value"] |
The attribute value ends with value. value is a complete word or part of a word. |
| [Attribute * = "value"] |
The attribute value is a substring of the specified value. |
Element Group
h1,h2{ color:red;}
Combine Selector
Em {color: red;}. project em {color: red;}. effecect. project em {color: red;}/* achieves the same effect, and the particularity is from low to high */
Chapter 10: select a font family for adding a style to a text
Font-family: name
Font names containing multiple words should be enclosed by quotation marks (single or double quotation marks.
Although the font-family attribute is inherited, several elements do not inherit the font settings of the parent element, including select, textarea, and input elements of the form. However, they can be forced to inherit.
Specify alternative font
You can list more than one font in the font-family attribute. Font-family: name, name2, name3 ..
Create Italic
Font-style: italic
Cancel Italic
Font-style: normal
Application bold format
Font-weight: bold (bold), font-weight: bolder (thicker), font-weight: light (finer), or enter 100 ~ A multiple of 900 between 100, 400 indicates normal width, and 700 indicates bold
Set Font Size
There are two ways to set the font size for the text of a webpage: Use pixels to specify the specific font size to be used, or use percentages, em, or rem to specify the size of the text relative to the parent element.
Em is recommended.
1em is always equal to the default font size, which is the working principle of em.
Rem always uses the root element as the reference.
Font-size: xx-small, font-size: x-small, font-size: small, font-size: medium, font-size: large, font-size: x-large, font-size: xx-large, or use numbers to add units or percentages
Set Row Height
The line height refers to the line spacing of a paragraph, that is, the distance between each line in a paragraph.
Line-height: n -- it is multiplied by the font size of the element to obtain the desired Row height.
Line-height: a -- here, a is the unit of em, px, pt.
Line-height: p % -- percentage of font size
Set all font values at the same time
You can use font to set the font style, width, variation, size, line height, and font family at the same time.
Font must contain at least the font size and family attributes.
Set color
Color: red;
You can use a style sheet to define colors by any combination of color names, hexadecimal values, RGB, HSL, RGBA, and HSLA values.
Set background
Background-color, background-image, background-repeat, background-attachment, and background-position. You can also use the background notation.
Background-repeat: duplicate background image. background-repeat: direction has four optional values: repeat, repeat-x, repeat-y, no-repeat
Background-attachment: controls whether the background image is scrolling along with the page. fixed: the background image is attached to the browser window. Even if visitors scroll through the window, the image will continue to be displayed. scroll: when a visitor scrolls the page, the background image moves. local: the background image moves only when the visitor scrolls the element of the background image.
Background-position: Specifies the position of the element background image.
Control spacing
It can increase or decrease the distance between words or letters. The former is called the word spacing, and the latter is called the word even distance.
Word spacing: word-spacing: length
Even distance: letter-spacing: length
Add indent
Text-indent attribute. You can specify how much space is left before the first line of a paragraph.
Align text
Text-align: left (right, center, justify), left-aligned, right-aligned, in the middle, aligned on both ends
Modify the case sensitivity of Text
The text-transform attribute defines the text case for the style.
Text-transform: capitalize -- uppercase for each letter
Text-transform: uppercase -- uppercase for all letters
Text-transform: lowercase -- lower case for all letters
Text-transform: none -- keep the text as it is
Use small uppercase letters
Small uppercase letters: uppercase letters, but smaller than lowercase letters. Use font-variant control.
Use: font-variant: small-caps
Cancel: font-variant: none
Decorative text
The text-decoration attribute is used to describe text by adding underscores or other types of lines.
Text-decoration: underline -- add an underline
Text-decoration: overline -- add dashes
Text-decoration: line-through -- add strikethrough
Cancel: text-decoration: none
Set blank Properties
Use white-space
White-space: pre -- enables the browser to display all spaces and carriage returns in the original text.