Three 002-CSS selectors

Definitions: CSS selectors that CSS has been defined for the selected fixed some grammar primary colors, its role is to select the elements that we want to set the style.

CSS selectors classifier:

 

 

 

 

Simple selector is divided into:

1. tag name selector: to select elements by a specific HTML tag names the name of [the current page will all be called to change the name of the label are selected]

2. Class name selector: select elements by class name tag

3.ID selector: name of the selected element by ID

Class name selector:

1. class name selector: a full page write requires a lot of labels are combined to achieve, because the type of HTML tags are limited, so a label of the same name appears more than once in one glance at this time if the label of the same name are these settings are not the same style, so directly using the tag name selector is not possible, then you need to select the class name is used.

2. Class name using the selector basic steps: .class class name

Defined HTML page structure, and then set the element we want to check the body class property, in setting the same elements we want to check their body class attribute values, namely the class name.

ID selectors:

1.ID selector: If you want to select one of a bunch of elements from among a certain element, you can use the ID selector, and the people on this ID ID number, is unique.

2.ID selector Use these steps: setting the element we want to select a body ID attribute to the ID property is set to a value, called an ID name to be called by a fixed syntax in style in: #ID name

Note: Requirements of the same name can not appear on a web page which ID [although effective, but can not do so]

ID name and class name naming rules:

  The name can not be pure digital, or start with a number

  The name can not contain Chinese or Chinese, although effective, but can not be used

  The name can not contain special characters, such as: ~! @ # ¥% ...... & * (), -_ except

  See name known Italian names do as much as possible

Simple selector summary:

1. Select the tag name and the default class name selector can select a plurality of disposable elements, ID name can only select a selector element

A tag body 2 may have both a class name and ID with name, class name can be the same name and ID, Name of the class can be written in a plurality of attribute values, separated by spaces between

 

Display elements Type:

In the HTML which itself defines a number of elements that show when the default page will have its own default display state, some elements such as the default width and height attributes in the case does not work, some elements will default on a separate line in the case show, this phenomenon is called the element display type. For memory, we will artificially display element is divided into three types: block element, the element row, the row block elements.

  1. The block elements: when there are a plurality of block elements at the same time, each block element are displayed on a separate line, and the default width of its high property can function in the case.

  2. inline elements: when a plurality of rows of elements present at the same time, these elements are displayed in a line, if a line fit will automatically wrap, default width and height of his property does not work.

  3. The inner row block elements: when there are multiple rows of block elements within the same time, these elements appear in a row, its width and height attributes to function by default.

Note: No need to remember

Layout tab added:

div we often use the page layout to a ditag (DIV + CSS), is one of the largest volume of a HTML tag inside it can hold a lot of other labels, is a block element

span we often use the page layout to a label, he generally used to store text, we would think that this label is very small, is inline elements

Paragraph tag can not wrap the title, because the browser can not parse correctly.

Display type conversion element

In the process of our web page layout often encounter some "special module" for this module is commonly used in some of our previous label when in use will be "semantic" does not correspond, so we can use the appropriate uh mandatory type label conversion, so that it can show the way into the draft design, different display property values ​​set in the CSS type of conversion to complete.

1. converted into block elements: display: block;

2. The block elements within a row turn: display: inline-block;

3. The inner row transfer elements: display: inine;

 

复合选择器

1.复合选择器:在实际的网页制作过程中,往往会出现很多结构层级嵌套很深的现象,而这种结构模块又很多,大家使用的标签名又一样,所以此时我们就可以通过复合选择器将这些简单选择器进行组合,从而让我们选择元素变得简单。

常见的复合选择器:

1.后代选择器:这种选择器就是以某一个元素为起点,将它作为祖先,然后不停的向下进行穿透查找,去选择它下边的后代元素。

起点元素 后代元素 ......{设置样式}

注:1)后代选择器当中的每个部分都可以采用任意的简单选择器代替

 2)不同的部分之间要用空格隔开

 3) ……就表示可以不停的向下层查找

2.并列选择器:

选择器权重总结:

1.权重:如果使用不同的CSS选择器去选中同一个元素,这些选择器对元素的控制能力

2.简单选择器:ID名》class名》标签名

3.复合选择器:给每个简单选择器都定义一个权重值,分别是:ID100),class10),标签名(1),将当前选择器中出现的权重值进行加求,最终的结果就是选择器的权重,数值大的权重大。

4.权重比的就是不同选择器对同一个元素的控制力比较。

补充:https://www.cnblogs.com/liontone/archive/2010/12/29/1920437.html

Guess you like

Origin www.cnblogs.com/qiuniao/p/11966053.html