1 CSS Introduction and specifications

1.1 the import type

The import mode loads the CSS file after the entire page is loaded, so this causes a problem. If the page is large, it will display the page with no style first, and then the style of the page will appear after a flash. This is an inherent flaw in importing.

<style type="text/css" media="screen">   
	@import url("CSS file");   
</style>
Copy the code






<link rel="stylesheet" type="text/css" href="index.css">
Copy the code

1.3 The difference between external chain and import

  • Link and @import both import external CSS files, but they are very different
  • Link is an HTML tag, and @import is exactly the CSS way to write it in a CSS file or style tag.
  • The loading order is also different. When a page is loaded, the CSS file referenced by link is loaded at the same time, while the CSS file introduced by @import is loaded after the page is downloaded.
  • When using JavaScript to control the DOM to change CSS styles, only use the link tag, because the import is not DOM controlled

1.4 the inline type

Use the style attribute to write CSS key-value pairs directly into the tag

<p style="width:100px; height:100px; background-color:red;" </p>Copy the code

1.5 embedded type

You can put it inside the head or body tag. It is recommended to put it inside the head tag under the title tag

2 Selector world

2.1 Basic selectors

2.1.1 Label selector

Select directly using element tags

p{color:red; 1} weight

2.1.2 Class selectors

An element is selected by its class name. An element can have more than one class name, all representing that the class name of the element is an attribute value in the class attribute of the element, for example

.sum{} => This selector has a weight of 10

2.1.3 ID selector

The element is selected by its ID name, the class name is the attribute value in the element ID attribute, for example

#sum{} => This selector has a weight of 100

2.1.4 Wildcard selector

Select all elements by *, including the root element *{} => weight less than 1, can be overwritten

2.2 Union selector

You can group selectors so that the grouped selectors share the same declaration. The selectors to be grouped are separated by commas. In the example below, we group all the heading elements. All title elements are green.

h1.h2.h3.h4.h5.h6{
	color:green;
}
Copy the code

2.3 Intersection selector

When two attributes belong to the same element, we can use the intersection selector to select the element exactly

<p class='name1 name2' id='id1'></p>
p.name1{}
p#id1{}
.name1.name2{}
Copy the code

2.4 Descendent selector

  • By defining styles based on the context of an element’s position, you can make the markup more concise, by separating strong elements in a list with Spaces into italics instead of the usual bold, and by defining a derived selector this way
  • Try not to have more than 3 background selectors. There is no need to write out every level, just the key node geeks
li strong{ font-style:italic; font-weight:normal; } <ol> <li> <strong> This is because the strong element is inside the li element. </stong> </li> </ol>Copy the code

2.5 Child selector

In contrast to descendant selectors, child selectors only select as child elements of an element, with the symbol curly braces

h1 > strong {color:red; } <h1>This is<strong>very</strong> important.</h1>Copy the code

2.6 Adjacent sibling selectors

Adjacent sibling selectors can select the element immediately after another element that has the same parent element

h1+p{
	margin-top:50px;
}
Copy the code

2.7 Attribute selector

Sets the style weight 10 for the HTML element with the specified attribute

You can set styles for having specified HTML elements, not just class and ID attributes

The following example styles all elements of the title property

[title]{color:red; }Copy the code

Properties and Value selectors The following example styles all elements with title=’ WJW ‘

[title=wjw]{color:red; }Copy the code

Style the form

input[type='text']{width:150px; display:block; background:yellow}Copy the code

2.8 Camouflage selector

  • A :link{color:#ff000} // Not accessed link
  • A: Visited {color::#ff000} // Have visited the link
  • A :hover{color:#ff000
  • A :active{color:#ff000} // Selected link

Weight 10 < < 11

The selector

The sample Sample description CSS version
.class  .demo Select all elements of class=”demo” 1
#id #firstname Select all elements whose ID =” firstName” 1
* * Select all elements 2
element  p Select all the

The element

1
element,element div,p Select all the

Elements and all

The element

1
element element div p choose

All inside the element

The element

1
element>element div>p Select the parent element as

Ownership of elements

The element

2
element+element div+p The choice is immediately following

Everything after the element

The element

2
[attribute] [target] Select all elements with the target attribute 2
[attribute=value] [target=_blank] Select all elements for target=”_blank” 2
[attribute~=value] [title~=flower] Select the title property to contain all elements of the word “flower” 2
[[attribute =value]](www.html.cn/book/css/se…) [lang|=en] Select all elements whose lang attribute value begins with “en”
:link a:link Select all unvisited links 1
:visited a:visited Select all the links that have been visited 1
:active a:active Select active links 1
:hover a:hover Select the link over which the mouse pointer is located 1
:focus input:focus Select the input element that gets focus 2
:first-letter p:first-letter Select each

Element first letter

1
:first-line p:first-line Select each

Element first line

1
:first-child p:first-child Select each of the first child elements that belong to the parent element

The element

2
:before p:before At the end of each

Element before the content

2
:after p:after At the end of each

Element after the content is inserted

2
:lang(language) p:lang(it) Select each with the value of the lang attribute starting with “it”

The element

2
element1~element2 p~ul Select before

Each of the elements

    The element
3
[attribute^=value]  a[src^=”https”] Select each whose SRC attribute value begins with “HTTPS”The element 3
[attribute$=value] a[src$=”.pdf”] Select all whose SRC attribute ends in “.pdf”The element 3
[attribute*=value] a[src*=”abc”] Select each of those whose SRC attribute contains the “ABC” substringThe element 3
:first-of-type p:first-of-type Select the first one belonging to its parent element

Each of the elements

The element

3
:last-of-type p:last-of-type Select the last element belonging to its parent

Each of the elements

The element

3
:only-of-type p:only-of-type Select one that is unique to its parent element

Each of the elements

The element

3
:only-child p:only-child Selects each of the unique child elements that belong to its parent element

The element

3
:nth-child(n) p:nth-child(2) Selects each of the second child elements belonging to its parent element

The element

3
:nth-last-child(n)  p:nth-last-child(2) Same as above, counting from the last child 3
:nth-of-type(n) p:nth-of-type(2) Select the second element belonging to its parent

Each of the elements

The element

3
:nth-last-of-type(n) p:nth-last-of-type(2) Same as above, but counting from the last child 3
:last-child  p:last-child Select each of the last child elements belonging to its parent element

The element

3
:root :root Select the root element of the document 3
:empty  p:empty Select each that has no child elements

Elements (including text nodes)

3
:target #news:target Select the current active #news element 3
:enabled  input:enabled Select each enabledThe element 3
:disabled input:disabled Select each disabledThe element 3
:checked input:checked Select each one that is selectedThe element 3
:not(selector) :not(p) Select the

Each element of the element

3
::selection  ::selection Selects the part of the element selected by the user 3
:out-of-range  :out-of-range Matches input elements whose values are outside the specified range 3
:in-range :in-range Matches input elements with values within the specified range 3
:read-write  :read-write Matches readable and writable elements 3
:read-only :read-only Matches the element that sets the “readonly” property 3
:optional :optional Used to match optional input elements 3
:required :required Matches elements with the “required” attribute set 3
:valid  :valid Matches elements whose input values are valid 3
:invalid :invalid Matches elements whose input value is illegal 3

3 Three features of the CSS (Overlap + Priority)

3.1 the cascading sex

Browsers parse CSS from top to bottom. In case of CSS conflicts, the CSS defined last takes precedence. Cascading refers to the stacking of multiple CSS styles. For example, when using inline CSS style sheet definitions

The tag size is 12 pixels and is defined in chained format

If the markup color is red, the paragraph text will appear 12 pixels red, which is an overlay of the two styles

3.2 priority

The priorities are as follows:! Important > style > weight value

Weight tips: Starting at 0, inline style +1000, an ID +100, an attribute selector /class or an element name +10, or a pseudo-element +1

Rule: Same weight: the selector that appears after is the last rule different weight, weight value takes effect

3.1.1 Basic selectors

type The weight
Tag selector /div 1
Class/class select.right 10
id 100
inline 1000
* 0-1
  • offspring
  • Their offspring
  • intersection
  • And set
  • Adjacent brothers
  • brother
  • attribute
  • pseudo-classes
  • Pseudo elements

Weight: The sum of the weights of each individual selector

.header ul li{
	/* Weight 12:10+1+1 */
  backgournd:red;
}

.header .right li{
	/* Weight 21:10+10+1 */
  backgournd:# 000;
}
Copy the code
  • The weight is equal

> * id > class > tag

  1. Weight is not equal to the case: whose power is important, listen to who
  2. In the case of equal weight: follow the nearest principle, the bottom cover the top
  3. Equal weight, do not follow the nearest principle, just want to listen to the above how to do
  4. ! important 1000

3.2.1 Weight Algorithm

First class: represents the inline style, such as: style= “”, weight is 1000. Second class: represents an ID selector, such as #content, with a weight of 0100. Third class: represents classes, pseudo-classes, and attribute selectors, such as.content, with a weight of 0010. Fourth class: represents type selectors and pseudo-element selectors, such as div P, with a weight of 0001. Wildcard, child selector, adjacent selector, etc. For example, *, >, +, the weight is 0000. Inherited styles have no weights. Priority from high to low: inline selector, ID selector, category selector, element selector.

! Important > inline style > ID selector > class selector inherited > > > > tag wildcard browsers default attributes important inline > > ID > pseudo classes | | attributes select > > > > false object wildcard tag inheritance

4 Three Features of the CSS (Inheritance Attributes)

4.2 Properties of non-inheritance

2 the display

  • inline
  • block
  • inline-block
  • table-cell
  • none

Specifies the type of box the element should generate

4.2.2 Text Attributes:

Vertical-align: vertical text alignment text-decoration: specifies the decorations added to the text text-shadow: specifies the text shading effect white-space: specifies the handling of whitespace unicode-bidi: specifies the text orientation

4.3.3 Attributes of box Model:

Width, height, margin , margin-top, margin-right, margin-bottom, margin-left, border, border-style, border-top-style, border-right-style, border-bottom -style, border-left-style, border-top-width, border-right-right, border-bottom-width, border-left-width, border-c Bor, bor, bor, bor, bor, bor, bor, bor, bor Der-left, PADDING, padding-top, padding-right, padding-bottom, padding-left

4.3.4 Background Properties

Background, background-color, background-image, background-repeat, background-position, background-attachment

4.3.5 Locating Attributes

Float, clear, position, top, right, left, min-width, min-height, max-width, max-height, overflow, clip, z-index

4.3.6 Generate content properties

Content, counter-reset, counter-increment

4.3.7 Outline Style properties

Outline-style, outline-width, outline-color

4.3.8 Page Style Properties

Size, page-break-before, page-break-after

4.3.9 Sound Style Properties

Pause -before, pause-after, pause, cue-before, cue-after, cue, play-during

4.3 Have the attribute of inheritance

4.3.1 Font Series properties

Font family: a set of fonts for elements; font weight: a set of fonts; font size: a set of fonts; Setting the font for small uppercase to display text means that all lowercase letters are converted to uppercase, but all letters using small uppercase will have a smaller font size than the rest of the text. Font-stretch: Stretches the current font-family. None of the major browsers support it. Font-size-adjust: Specify an aspect value for an element so that the x-height of the preferred font is maintained.

4.3.2 Text series attributes

Text-align: text-align line-height: word-spacing: increasing or decreasing the space between words Text-transform: controls the case direction of the text. Specifies the direction of the text. Color: specifies the text color

4.3.3 Element visibility

visibility

4.3.4 Table layout properties

Caption -side, border-collapse, border-collapse, empty-cells, table-layout

4.3.5 List Layout Attributes

List style-type, list style-image, list style-position, list style

4.3.6 Generate content properties

quotes

4.3.7 Cursor Properties

cursor

4.3.8 Page Style Attributes:

Orphans, Page, Page-break-inside, Windows, and orphans

4.3.9 Sound Style Properties:

Speak, speak-punctuation, speak-Numeral, speak-header, speech-rate, volume, voice-family, Pitch, pitch-range, stress, richness, az Imuth and elevation

4.4 Attributes that all elements can inherit

2. Cursor attributes: cursor

4.5 Attributes that inline elements can inherit from

2. Text series attributes except text-indent and text-align

4.6 Attributes that block-level elements can inherit

1, text-indent, text-align

5 CSS box model

5.1 CSS Box Model Diagrams

  • Margin: from the outside
  • Border: border
  • Padding: padding

5.2 Width and height of the CSS box model

  1. Px pixel write down 2. % units of dynamic calculation (adaptive response)
* {margin:0;
  padding:0;
}
.banner img{
	width:100%;
}
Copy the code

5.3 Inner Margin padding and abbreviation

5.4 Skills of using border line border

Border: width of the border Border type Border line color

5.4.1 Type of border line

5.4.2 Type of border line

  • Solid solid line
  • Dashed line
  • Dotted dotted line

5.4.3 Color of border line

black white
Color English black white
# # 000 #fff
rgb RGB (0, 0) RGB (255255255).

Border-top border-right border-bottom border-left border-left if there is no known direction, all four directions are equal

5.4.4 Remove the border

Border :0 If the border attribute has only the border segment, the type and color of the border will be invalid

5.4.5 Interview Questions (Draw a triangle)

/ * triangular arrowheads principle: any adjacent two edge of the square Then rotate an Angle to get any direction, we need the size of the unit to rotate arrows deg Angle rotation Angle triangle from a square of wide high to control the thickness of the triangle is a border line to control the color of the triangle is the color of the border lines to control the * /<div class="arrow"></div>

<style>.arrow{ width: 0px; height: 0px; margin-top: 50px; margin-left: 50px; border-width:0 30px 30px; border-style:solid; border-color:transparent transparent #333; transform: rotate(90deg); // control Angle}</style>
Copy the code

5.5 the padding

It’s in the same direction as the padding

5.6 Margin negative use skills

Structurally unchanged, you can switch div order

5.7 Padding and margin

Padding is the padding that affects the actual size of the element that we see in the browser and it makes the content of the element bigger and it doesn’t matter what the other elements are. Margin is the margin that doesn’t affect the actual size of the element that we see in the browser and it doesn’t make the content of the element bigger and the space between it and another element

5.8 Calculation formula and use skills of box model

Actual element width

Width width + padding-left/padding-right+border-left/border-right

Actual height of element

Height height + + padding – top/padding – bottom border – top/border – bottom

If you add the padding and border values, subtract the padding and border values from the width and height values otherwise the content will overflow

6 landing the mechanism

BFC stands for Block Formatting Context. It is a concept defined by the CSS2.1 specification regarding CSS rendering positioning. It is a separate rendering area, with only block-level box participation, which dictates how the internal block-level box is laid out and has nothing to do with the outside of the area.

6.1 BFC Layout Rules

  1. The internal boxes will be placed vertically, one on top of the other;
  2. The vertical distance of the Box is determined by margin. The margins of two adjacent boxes belonging to the same BFC will overlap.
  3. The left side of the margin box of each element touches the left side of the border box containing the block (for left-to-right formatting, otherwise the opposite). This is true even if there is a float. ;
  4. BFC areas do not overlap float boxes and are often used to clear floats and layouts. ;
  5. A BFC is a separate container on a page, and the child elements inside the container do not affect the outside elements. And vice versa. ;
  6. When calculating the height of the BFC, the floating element is also involved;

6.2 BFC elements are generated

  • The root element or other element containing it;
  • floating(elements offloatDon’t fornone);
  • Absolute location element(elements ofpositionforabsoluteorfixed);
  • Inline blocksinline-blocks(elements ofdisplay: inline-block);
  • Table cell(elements ofdisplay: table-cell, default attributes of HTML table cells);
  • overflowThe value of thevisibleThe element;
  • Flex boxes(elements ofdisplay: flexorinline-flex);

6.3 BFC Scope

The scope of the BFC is described in MDN as follows.

A block formatting context contains everything inside of the element creating it that is not also inside a descendant element that creates a new block formatting context.

A BFC contains all the children that created the context element, but not the inner elements that created the child of the new BFC. Insert a piece of code to make it easier to understand

<div class='div_1 BFC'>
     <div class='div_2'>
         <div class='div_3'></div>
         <div class='div_4'></div>
      </div>
      <div class='div_5 BFC'>
	       <div class='div_6'></div>
         <div class='div_7'></div>
     </div>
</div>
Copy the code

Div_1 creates a block format context that includes div_2, div_3, div_4, and div_5. That is, the children of div_2 also belong to the BFC created by div_1. But since div_5 creates a new BFC, div_6 and DIV_7 are excluded from the outer BFC. This means that an element cannot exist in more than one BFC at the same time. One of the most important effects of the BFC is to isolate the elements inside the BFC from the elements outside, so that the positioning of the elements inside and outside does not affect each other. This is a feature used to clear floats with BFC.

6.4 Common BFC modes:

6.4.1 Height collapse of the parent due to Child Floating

<style type="text/css">.box{ width: 900px; background: black; height: 300px; }. Box1 {height: 300px; width: 300px; background: red; float: left; } .box2{ height: 300px; width: 300px; background: blue; float: left; }</style>.<div class="box">
    <div class="box1"></div>
    <div class="box2"></div>
</div>
Copy the code

The above code defines 3 blocks. A parent contains two subsets, but the background color of the parent cannot be displayed because the subset-element float causes the height of the parent to collapse.









6.4.2 Child margin-top Triggers BFC from the parent band to the parent band

If one box has a top margin and the other has a bottom margin, there will be the overlapping problem of margin margin. Margin rewriting of parallel boxes => overlap of double margins -> Taking a large value is not the sum of them, that is, who listens to who most

To move the small red block in the black block down a bit, use margin-top directly and the black block moves down together.

<style type="text/css">
        .box{
            width: 300px;
            height: 300px;
            background: black;
        }

        .box1{
            height: 100px;
            width: 100px;
            background: red;
            margin-top: 50px;
        }

    </style>.<div class="box">
    <div class="box1"></div>
</div>
Copy the code

After setting the BFC, the red block will float correctly

Compatibility problem of margin: transfer problem of margin top

Margin-top added to the small box does not achieve the spacing between the small box and the big box, but instead transfers the space to the big box, resulting in the overall downward movement to solve the compatibility problem

  1. Overflow :hidden resolve margin-top pass-through (no overflow hidden here)
  2. Padding-position :1px This method affects the actual width and height, and subtracts the width/height so as not to affect the actual width and height
  3. Border-top :1px; border-top:1px; border-top:1px; border-top:1px; border-top:1px
  4. Change the margin-top value of the child element to the padding-top value of the parent element to avoid pass-through problems with margin-top values

7 Background

7.1 Background Properties

Background abbreviations can unload all background attributes in a statement. Background images support the introduction of multiple images. The main attributes are: background-color background-image background-repeat background-position backgournd-attchment backgournd-size backgournd-origin backgournd-clip


7.2 Background Color

background-color

  • Specify the background color to use for example :background-color:#ffcc00
  • We can abbreviate it to background
  • Backround-color cannot be inherited; its default value is trandsparent. Trandsparent means transparent. That is, if an element does not specify a background color, the background is transparent so that the background of its ancestor elements is visible.
  • Transparent Specifies that the background color should be transparent, the default.
  • Inherit specifies the background color, which should be inherited from the parent element
<style>.box{ width:650px; height:32px; background-color:orange; / / color color: # FFF; // Use the color text-aligh:center; } div{width:200px; height:200px; backgournd-color:darkbule; margin:0 auto; // Auto block element horizontal center line-height:200px; // Vertical center}</style>
Copy the code

7.3 Background Image

background-image

  • Url (‘ image’s URL path address ‘) The URL of the image
  • None indicates that no images are blocked on Beijing, which is the default
  • Inherit specifies that the background image should be inherited from the parent element
  • An element can introduce multiple background images, specifying one or more background images to use. By default, background-image is placed in the upper left corner of the element, and the vertical horizontal direction is repeated.
  • backgournd image:url(‘pic.png’),url(‘pic2.png’)… .
  • The backgournd image property cannot be inherited

7.4 Background Repetition

  • Specify how to repeat the background image, by default, the vertical and horizontal directions of the background-image
  • The repeat background image is vertical and horizontal. This is the default
  • Repeat -x only repeats the background image horizontally
  • Repeat -y only the vertical position repeats the background image
  • No-repeat background-image is not repeated
  • Inherit specifies that the background repetition should be inherited from the parent element
.logo{ width:300px; height:300px; backgournd-image:url('.. /xxx/png'); backgournd-repeat:repeat x; // Tiling mode (repeat)}Copy the code

7.5 Background Location

  • The backgournd-position property sets the starting position of the background image.
  • Xpos ypos is the horizontal position of the first value, and the second value is vertical. The top left corner is 0. Units can be length values px, keywords, and percentiles
  • The keywords appear in pairs left right top bottom center. If only one keyword is specified, the other values will be “center”.
  • X % y% the first value is horizontal and the second value is vertical. The top left corner is 0%, 0%.
  • Inherit specifies that background-position property Settings should be inherited from the parent element
.logo{ width:400px; height:400px; backgournd-color:#3385ff; // Backgournd-image :url('./xxx.png'); backgournd-repeat:no-repeat; backgournd-position:50px 50px; // the larger the X-axis is, the more the X-axis is, the more the X-axis is, the more the X-axis is, the more the X-axis is, the lower the X-axis is.Copy the code

Often used in Sprite images

7.6 Background Association

backgournd-attachmen

  • Sets whether the background image is fixed or scrolls along the rest of the page
  • The background image scrolls with the rest of the page. This is the default
  • Fixed The background image is fixed
  • Inherit specifies that background-attachment Settings should be inherited from the parent element
*{ padding:0px; margin:0px; } .banner{ width:100%; height:800px; backgournd:url(.. /xxx.png) no-repeat } .banner01{ width:100%; height:800px; backgournd:url(.. /xxx.png) no-repeat } .banner02{ width:100%; height:800px; backgournd:url(.. /xxx.png) no-repeat backgournd-attachmen:fixed; // Can be fixed}Copy the code

7.7 Setting the size of the background image of the object

background-size

  • Specifies the background image size with the length value. Negative values are not allowed;
  • Specifies the background image size as a percentage. Negative values are not allowed.
  • Auto The true size of the background image
  • Cover scales the background image to completely cover the container, and the background image may exceed the container.
  • Contain scale the background image to the same width or height as the container
.pic{ width:200px; height:1600px; background:url('.. /xx.png') background-size:300px 300px; // X-axis Y-axis}Copy the code

7.8 Sets the clipping area of the object’s background image

background-clip

  • Padding-box: Clipping the background from the padding area (excluding the padding);
  • Border-box: Crop the background outward from the border area (excluding the border)
  • Bontent-box: Crop the background outward from the Content area
  • Text: Crop out from the shape of the foreground content (such as text) as the clipping area, so the geek achieves mask effects such as using the background as a fill color.
.pic{ width:200px; height:1600px; background:url('.. /xx.png') background-size:300px 300px; // X-axis Y-axis backbound-clip :border-box; }Copy the code

7.9 Setting the Reference Origin (Position) of the Background Image

background-orign

  • Padding-box: Displays the background image from the padding area (including the padding)
  • Border-box: Displays the background image starting from the border area
  • Content-box: Displays the background image from the Content area

8 voerflow:hidden

8.1 Overflow Hiding

Anything beyond the content is hidden

p{ width:300px; height:10px; overfolw:hidden; }...<p>xxxxxxxxxxxxxxxxxxxxxxxx...... xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.....</p>
Copy the code
  1. To understand the effects of the float
  2. Solve margin-top transfer problem

A method to display a line of multiple elements

9.1 Methods for displaying a line of multiple elements

  • display:inline; // Convert to inline element but does not work when the width and height attribute is set
  • display:inline-block; // Block allows elements to be displayed on a single line, but it is subject to space/line breaks, which creates a default spacing
    • Remove whitespace and line feed effects so labels are all on one line (not recommended for bad reading)
    • Add a font size:0 to the parent element and a font size:14px to the child element. (But we can also find a problem: if there is text in the element, the text disappears, and then add an attribute to the child element.)
  • float:left/rigjt; // But we are clear float

** [display:inline-block element characteristics]**

  • Arrange the boxes horizontally
  • The Vertiacal-align attribute affects the inline-block element, which you may set to top
  • You need to set the width of each column
  • If there are Spaces between elements in the HTML source, there will be gaps between columns
*{ margin:0px; padding:0px; } .content1{ display:inline; width:200px; height:100px; backgournd-color:yellow; } .content2{ display:inline; width:200px; height:100px; backgournd-color:yellow; }... <div class="content1"> <div class="content2"> </div>Copy the code

Inline-block is not compatible with IE7

Let the block element be rendered inline directly (with the display:inline attribute), and then trigger the layout of the block element (such as the zoom:1 or float attribute). The following code

/* Recommended :IE6, 7*/ div {display:inline-block; *zoom:1; *display: inline; } /* Recommended */ div {display:inline-block; _zoom:1; _display:inline; }Copy the code

Explanation: Display: Inline block takes care of Internet Explorer 8+, this is normal Settings, under the lower version of Internet Explorer, there are two conditions, one is inside the line, one is set to width and height, trigger layout to set width, while div width is set to yellow air, layout is not set to horizontal. Display :inline will not trigger the layout, so zoom:1 will trigger the layout again, resulting in a cross-domain set width and height of the inline element

10 Ellipsis in the text

10.1 Necessary Conditions for Ellipses in Single Line Text (Interview questions)

* {margin:0;
  padding:0;
}

h2: {width:600px;
  height:30px;
  /* Single line text appears to omit good prerequisite */
  overflow:hidden;/* Overflow hide */
  white-space:nowrap;/* Enforces text not to break */
  text-overflow:ellipsis;/* How to hide text: hide it with ellipsis */
}

Copy the code

10.2 Necessary Conditions for Ellipses in Multi-Line Text (Interview questions)

h2{
	width:600px;/ * * / width
  display:-webkit-box;/* Elastic box model */
  -webkit-line-orient:vertical;/* Specifies the ranking of elements by vertical order */
  -webkit-line-clamp:2;/* The number of lines needed to display the number of lines */
  overflow:hidden;/* Overflow hide */
}
Copy the code

Floating element features

11.1 Characteristics of float elements

  1. Floating elements are displayed on a single line
  2. When the property value is set to left, the floating elements are arranged from left to right of the parent box, and when the property value is set to right, the floating elements are arranged from right to left of the parent box
  3. Floating elements automatically have the attributes of block-level elements
  4. Float elements out of the document flow
  5. Children within a float element do not inherit the float attribute
  6. The element below the floating element does not recognize the height and position of the floating element, so display:block is disabled

Document flow and disengagement document flow

12.1 introduction

  • Document flow: Refers to the automatic left to right, top to bottom streaming of elements during layout. The final form splits into rows from top to bottom and emptying elements from left to right in each row
  • Each non-floating block-level element has an exclusive row, and the floating element floats on one end of the row as specified. If the current line is not enough, a new line will float again
  • Inline elements do not occupy a single line; Almost any element (including block-level, inline, and list elements) can generate child rows for placing child elements
  • Standard document flow level: divided into two levels, block level elements and inline elements;
  • Out-of-document flow: This element is not recognized by normal elements in the document flow (out-of-document elements float parallel to the document flow)

Normal document flow: left to right and top to bottom Document flow can be hierarchical: inline elements and accounting elements Inline elements are left to right and block level elements are top to bottom

12.2 Interview questions: What are the characteristics of inline elements and block-level elements? Please list the labels.

Requirement: Block level elements (such as div) are required to be displayed on a single line out of the document flow: the normal arrangement of elements is broken

Out of influence of document flow:

  1. float
  2. positioning

12.3 Impact or Negative Effect of Floating Parameters

  1. Setting the background color attribute does not work
  2. The border attribute for the parent element is not stretched
  3. Setting the padding property for the parent element is also not supported

12.4 How do I Clear floating Information

  1. Manually add a fixed height to the parent element of the float element (not recommended)
  2. Set overflow: Hidden/Auto for the floating element’s parent
  3. Append the closing tag of the parent element of the floating element with an element characteristic (we usually use div), and make the element clear:both
  4. ClearFix pseudo-elements to clear floats (this method is most commonly used in projects)

Using pseudo-elements :after clear floating fixed code; Just to clear the float we add a.clearfix to the parent of the float element

12.5 Let the elements disappear from our view

  1. Transparency opacity: 0; [0 ~ 1]
  2. Display: hidden node
  3. Height: 0 and overflow: hidden
  4. Line-height :0 and overflow:hidden(if no height is set)
  5. visbility:hidden; Make all visible elements hidden
  6. Margin /padding is large enough to make it disappear
  7. Use the transform property to make the transform coordinate large enough