CSS Overview
CSS is a cascading style sheet (cascading style Sheets) used to define the display of a Web page. It can solve the duplication of style definition in HTML code, improve the maintainability of later style code, and enhance the function of the Web page display effect. Simple sentence: CSS separates the content of the Web page from the display style, which improves the display function.
So how is CSS and HTML combined in the code of the Web page? In four ways: Style property, style label, import, and link.
Four ways to combine CSS with HTML
☆ 1, style attribute mode
This approach is seldom used, because it is similar to HTML.
Generally use the following 3 kinds.
<p style="background-color:#FF0000; color:#FFFFFF"> </p>
☆ 2, style label way
<style type=”text/css”> p { color:#FF0000;}</style>
☆ 3, import method
<style type="text/css"> @import url(myDiv.css)</style>
☆ 4, Link way
<link rel="stylesheet"type="text/css" href="css_3.css" media="screen"
Related syntax
☆ Style Priority
From top to bottom, from outside to inside. The priority level is from low to high. --In summary, the general situation is that it will be loaded later, but there is also a detail priority problem (as discussed later).
☆CSS Code Format
Selector Name {property Name: property value; Property Name: Property value; ...}
Separating attributes from attributes by semicolons
property is concatenated with the property value directly by using a colon
If a property has multiple values, then multiple values are separated by a space.
Selector Selector
Is the tag that specifies the CSS to function, and the name of that tag is the selector. Select which container (the label itself is the container that encapsulates the data).
☆ There are three kinds of selectors:
1) HTML tag name selector. The tag name of the HTML is used.
(i.e. directly using tags in html)
2) class selector. The class attribute in the tag is actually used.
(Front Plus: #)
3) ID selector. In fact, the id attribute in the tag is used.
(Front Plus:.)
Each label defines the class attribute and the id attribute. It is used to identify labels and to facilitate the operation of labels.
In the definition, the class attribute values for multiple labels can be the same, and the ID values are unique because JavaScript is used frequently.
☆ Priority of the selector
Tag name Selector < class selector < ID selector < Style property
Extended Selector
☆ Association Selector
tags can be nested, so you can use this selector to show different styles for different labels in the same tag. For example:
p { color:#00FF00;}p b { color:#FF000;}<p>P标签<b>湖南城市学院</b>段落样式</p><p>P标签段落</p>
Set the P label.
Set the B label in the P tab.
☆ Combination Selector
Define the same style for multiple selectors. For example, if we want to set the same style for the "tags in div " and "Class name CC" Areas, you can define the following combination selectors:
.ccdivb{/*不同选择器之间用逗号分开*/ background-color:#0000ff; color:#fff;}
Set the label for Id= "CC" and the B tag under the div tag.
☆ Pseudo Element Selector
In fact, some of the pre-defined selectors in HTML are called pseudo-elements.
Format: Tag name: pseudo element. Class name tag name. Class name: pseudo-element.
Pseudo-elements in hyperlink a tags:
A:link hyperlink is not clicked.
The state after the a:visited is visited.
A:hover the cursor to the status on the hyperlink (not clicked).
A:active the status when the hyperlink is clicked.
Pseudo-elements in the paragraph P tag:
P:first-line the first line of text in a paragraph.
P:first-letter the first letter in a paragraph.
Custom Pseudo-elements:
: Focus-focused element (actually a bit like after-click Listening)
div:hover{ background-color:#f00; color:#fff; }
CSS's Box model
◇ Frame (border)
On Border-top
Next Border-bottom
Left Border-left
Right Border-right
◇ Inner Patch (paddings): Inner margin
On Padding-top
Next Padding-bottom
Left Padding-left
Right Padding-right
◇ External Patch (Margins): Margin
On Margin-top
Next Margin-bottom
Left Margin-left
Right Margin-right
Border (border)-the bounds of the enclosing graphic for this element content
Inner Patch (paddings): padding-The distance of the element boundary from its own content text
Outer Patch (Margins): margin-the distance from the boundary (border) of the other element to the boundaries of the element itself
☆css Layout--Floating
◇float:none | Left | Right
None: Default value. object does not float
Left: Text flows to the right of the object
(This object flows to the left)
Right: Text flows to the left of the object
(This object flows to the right)
◇clear:none | Left | Right | Both
None: Default value. Allowed to have floating objects on both sides
Left: does not allow floating objects
Right: Do not allow floating objects
Both: Floating objects are not allowed
(If a floating object is not allowed and there is just one object floating over it, which needs to occupy one row of the object, the object moves, giving the floating object a row so that they do not overlap.)
☆css Layout--positioning
◇position:static | Absolute | Fixed | Relative
Static: The default value. No special positioning, the object follows the HTML positioning rules.
Absolute: Drag objects from the document stream, using left, right, top, bottom, and other properties to be absolutely positioned relative to the closest one of its most positioned parent. If no such parent object exists, then the body object is based. And its cascade is defined by the Z-index property.
Fixed: not supported. Object positioning is in absolute (absolute) mode. But there are some rules to follow.
Relative: objects are not stackable, but will be offset from the normal document flow based on properties such as left, right, top, bottom, and so on.
absolute-absolute positioning.
If an object uses absolute positioning, it is actually equivalent to floating on another level (overlapping), while the original level of its own position is covered by other modules.
relative-relative positioning.
If an object uses relative positioning, it also corresponds to the object floating on another level (overlapping), but the original level of its own position will not be covered by other modules.
☆css layout--picture and text mixed row
☆CSS layout--Image signature
(these 2 implementations are actually implemented using a box model, absolute positioning or relative positioning)
CSS also has a lot of knowledge points, you can write more, see the API is familiar with the basic syntax is so much ~ ~
CSS---network programming