These are my own summary of the knowledge in the learning process, this article I will share with you in the form of interview questions, hope to be of service, this paper length is longer, if you read carefully, and read it over and over again, I believe in your learning or an interview, I would have certain help, at the same time hope you comment!

1. What about the standard CSS box model? What’s the difference between the box model and the earlier VERSION of IE?

There are two types of box models: the standard box model and the IE box model

** Standard (W3C) Box Model: **

Width height refers to the width and height of content

** content+padding+border + margin, **

Width height refers to the width and height of the content+padding+border section

Extension of the question:

** CSS how to set these two models? 六四事件
box-sizing : content-box  
box-sizing : border-box
Copy the code

** JS how to set the width and height corresponding to the box model? 六四事件

dom.style.width/height; / / set for the inline style dom currentStyle. The width/height; Window.getcomputedstyle (dom).width/height; // Only IE supports window.getComputedStyle(dom).width/height; / / good compatibility dom. GetBoundingClientRect (). The width/height; // Place of application: calculates the absolute position of an elementCopy the code

** Real example problem (explain margin overlap according to box model)? 六四事件

This example is parent-child margin overlap, as well as margin overlap for sibling elements

<style> html *{ padding: 0; margin: 0; } #sec{ background: #f00; overflow: hidden; // Create a BFC, block level format context}.child{height: 100px; margin-top: 10px; background: yellow; } </style> <section id="sec"> <article class="child"></article> </section>Copy the code

** BFC (Margin Overlap solution)? 六四事件

2. Box-sizing?

The default value is content-box context-box. The default value is content-box context-box. The default value is content-box context-box, which is the W3C standard box model. ** Set the height/width attribute of the element to the content + border + padding section

3. Understanding of block formatting context (BFC)?

(A concept in the W3C CSS 2.1 specification that is a stand-alone container that determines how elements position their content and how they relate and interact with other elements.)

A page is made up of many boxes. The type of the element and the display attribute determine the type of the Box.

Different types of boxes participate in different Formatting contexts (containers that determine how documents are rendered), so elements inside the boxes are rendered in different ways. This means that elements inside and outside the BFC don’t interact with each other.

The BFC defines how the internal Block Box is laid out.

Positioning scheme:

  1. The internal boxes are placed vertically one after the other.
  2. The vertical distance of Box is determined by margin. Margins of two adjacent boxes belonging to the same BFC will overlap.
  3. The left side of each element’s margin box touches the left side of the containing block’s border box.
  4. The region of the BFC does not overlap with the float box.
  5. The BFC is a separate container on the page, and the child elements inside the container do not affect the outside elements.
  6. When calculating the height of the BFC, the float element is also calculated.

A BFC can be triggered if one of the following conditions is met

  1. The root element, which is HTML
  2. Float does not have a value of None (default)
  3. Overflow value is not visible (default)
  4. The display value is inline-block, table-cell, and table-caption
  5. The value of position is absolute or fixed

For more on the BFC, see my articleWhat is the BFC? What’s the use?

4. What are the CSS selectors? Which attributes can be inherited? How to calculate the CSS priority algorithm?

CSS selectors:

1. Id selector (# myid)

2. Class selector (.myClassName)

3. Tag (element) selectors (div, h1, p)

4. Adjacent selector (H1 + p)

5. Sub-selector (ul > Li)

6. Progeny selector (Li A)

7. Wildcard selector (*)

A [rel = “external”]

Hover (A :hover, Li :nth-child)

Pseudo element selector, group selector.

Inheritance:

Inheritable styles: font-size, font-family, color, ul, li, dl, dt, dd;

Non-inheritable styles: border, padding, margin, width, height

Priority (proximity principle) :! important > [ id > class > tag ] ! Important has a higher priority than inline

Priority algorithm calculation

Priority nearest principle, as in the case of weight style definition of the nearest prevail

! important>id >class>tag

Important has a higher priority than inline

Element selector weights: element label (derivation selector) : 1, Class selector: 10, ID selector: 100, inline style maximum weight, 1000

  1. ! Styles declared important have the highest priority and are evaluated if they conflict.
  2. If the priorities are the same, the last appearing style is selected.
  3. Inherited styles have the lowest priority.

5. What pseudo-classes are added in CSS3?

P :first-of-type Selects the first of its parent elements

Each of the elements

Elements.

P :last-of-type selects the last element belonging to its parent

Each of the elements

Elements.

P :only-of-type Select the unique of its parent element

Each of the elements

Elements.

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

Elements.

P :nth-child(2) Selects each of the second children that belong to its parent element

Elements.

:enabled

:disabled Specifies whether the form control is disabled.

:checked, the button or check box is checked.

:before adds content before an element and can also be used to clear the float

:after adds content after the element

6. How to center a div? How to center a floating element? How do I center an absolutely positioned DIV? How to center an img position

Horizontal center div:

border: 1px solid red;
margin: 0 auto; 
height: 50px;
width: 80px;
Copy the code

A floating element centered horizontally or vertically

The first: unknown element width and height

<div class="outer"> <span style>.outer{width:300px; height:300px; position:relative; background-color:#ccc; } span{ float:left; position:absolute; backgroond-color:red; top:50%; left:50%; transform:translate(-50%,-50%); } </style>Copy the code

Second: known element width and height

<div class="outer"> <span style>.outer{width:300px; height:300px; position:relative; background-color:#ccc; } span{ float:left; position:absolute; backgroond-color:red; width:150px; height:50px; top:50%; left:50%; margin:-25px 0px 0px -75px; } </style>Copy the code

Img (display: table-cell or position)

<div class="outer">        
    <img src="nz.jpg" alt="">    
</div>
<style>        
    .outer{            
        width: 300px;           
        height: 300px;            
        border: 1px solid #cccccc;            
        display: table-cell;            
        text-align: center;            
        vertical-align: middle;        
    }        
    img{            
        width: 150px;            
        height: 150px;        
    }    
</style>
Copy the code

Absolutely positioned divs are centered horizontally and vertically:

border: 1px solid black;
position: absolute;
width: 200px;
height: 100px;
margin: auto;
left: 0;
right: 0; 
top:0;
bottom:0;
Copy the code

An even more elegant way to center is to use the flex layout. Click on my article Mastering Flex Layouts, which is enough **

For more centered questions, check out my postSeveral methods of centering divs

7. What are the values of display? Explain their role?

value describe
inline The default. This element is shown inline, with no newline before or after the element.
block This element is displayed as a block-level element with a newline before and after it.
none This element is not shown (hidden).
inline-block Inline block elements. (Added in CSS2.1)
list-item This element is displayed as a list.
table This element is displayed as a block-level table (similar to table) with a newline before and after the table

8. The value of position?

value describe
absolute

Generates an absolutely positioned element, positioned relative to the first parent element other than a static location.

The position of the element is specified by the “left”, “top”, “right”, and “bottom” attributes.

fixed

Generates fixed-positioned elements that are positioned relative to the browser window. (Old IE does not support)

The position of the element is specified by the “left”, “top”, “right”, and “bottom” attributes.

relative

Generates a relative positioned element, positioned relative to its normal position, without leaving the document flow.

Therefore, “left:20” adds 20 pixels to the left position of the element.

static The default value. Without positioning, the element appears in the normal document flow (ignoring the top, bottom, left, right, or Z-index declarations).
inherit Specifies that the value of the position attribute should be inherited from the parent element.

CSS positioning has a new attribute, sticky positioning sticky, it is mainly used on the scroll event monitoring;

Viscous positioning can be considered a mixture of relative positioning and fixed positioning. Elements are positioned relative until they cross a certain threshold and then fixed. Such as:

#one { position: sticky; top: 10px; }
Copy the code

The elements are positioned relative until the viewport scrolls to the top of the elements less than 10px away. After that, the element is fixed 10px from the top until the viewport rolls back below the threshold.

For more information on sticky, please click hereIntroduction to Viscous Positioning

9. What are the new features of CSS3?

  1. Added various CSS selectors :not(p) selects every non-P element; P :empty selects every P element that does not have any children (including text nodes)

  2. Borders:

    div{ border:2px solid; border-radius:25px; Box-shadow: 10px 10px 5px #888888; Border-image :url(border-.png) 30 30 round; // Set shorthand properties for all border images. }Copy the code
  3. Background background-clip (specifies the drawing area of the background image), background-origin, background-size

    div{ background:url(img_flwr.gif); background-repeat:no-repeat; background-size:100% 100%; Background-origin :content-box; background-origin:content-box; } body{background-image:url(img_flwr.gif), URL (img_tree.gif); }Copy the code
  4. Linear Gradients down/up/left/right/diagonally

    background: linear-gradient(direction, color-stop1, color-stop2, ...) ;Copy the code
  5. Text-shadow, textwrap, word-break, word-wrap;

  6. * * * * the transform 2 d transformation: scale (0.85, 0.90) | translate (0 px, – 30 px) | skew (9 deg, 0 deg) | rotate () 3 d conversion perspective (); Transform applies a 2D or 3D transform to an element;

  7. Transition the transition

  8. animation

  9. Multi-column layout

  10. The box model

  11. Flex layout

  12. ** Multimedia query ** defines two sets of CSS that take different properties when the browser size changes

For more new features in CSS3 and HTML5, check out the new features in CSS3 and HTML5

10. Please explain CSS3 flexbox (elastic box layout model) and its application scenario?

The purpose of this layout model is to provide a more efficient way to lay out, align, and allocate space for items in a container. In a traditional block layout, blocks are arranged vertically from top to bottom. The inline layout is arranged horizontally. Elastic box layouts have no such inherent directional restrictions and can be manipulated freely by the developer. Trial scenario: The flexible layout is ideal for mobile front-end development and is perfectly supported on Android and ios.

For more information on Flex layouts, see my article Do you really know Flex layouts?

11. How does it work to create a triangle with pure CSS?

! [](https://user-gold-cdn.xitu.io/2019/4/27/16a5dcb4c320fc4f? w=110&h=88&f=png&s=514)

First, you need to set the width and height of the element to 0. Then set the border style.

width: 0;
height: 0;
border-top: 40px solid transparent;
border-left: 40px solid transparent;
border-right: 40px solid transparent;
border-bottom: 40px solid #ff0000;
Copy the code

12. How to design a full screen layout?

The first real product:

  1. The height and width of the three pieces are determined;
  2. Margin: 0 auto; In the middle.
  3. The next two use float or inline-block without breaking lines;
  4. Use margin to center them.

The second full-screen font layout: set the top div to 100% and the bottom div to 50% wide, then use float or inline to make them non-newline.

13. Common compatibility problems?

  1. The default margin and padding are different for different browsers. The solution is to add a global

    *{margin:0; padding:0; } to unify;

  2. IE6 two-sided margin bug: When block property tag float is followed by margin, IE6 shows margin is larger than set. Hack: display: inline; Convert it to an inline property. The method of progressive recognition gradually excludes the part from the whole. First, the clever use of the “9” tag separates Internet Explorer from all situations. Then, use “+” again to separate IE8 from IE7, IE6, so that IE8 has been identified independently. The method of progressive recognition gradually excludes the part from the whole. First, the clever use of the “9” tag separates Internet Explorer from all situations. Then, use “+” again to separate IE8 from IE7, IE6, so that IE8 has been identified independently.

    { background-color:#f1ee18; Background-color :#00deff\9; /*IE6, 7, 8 */ +background-color:#a200ff; /*IE6, 7 */ _background-color:#1e0bd1; /*IE6 */}Copy the code
  3. Set a small height label (usually less than 10px), and in IE6, IE7, the height is higher than the self-set height. Hack: Set overflow:hidden for tabs that exceed the height; Or set the line height to be less than the height you set.

  4. In IE, you can use the method of obtaining general attributes to obtain custom attributes, or you can use getAttribute() to obtain custom attributes. In Firefox, you can only use getAttribute() to get custom attributes. Solution: Use getAttribute() to obtain user-defined attributes.

  5. By default, text smaller than 12px is forced to display as 12px. You can add the CSS property -webkit-text-size adjust: None; To solve.

  6. The hover style does not appear after the hyperlink is accessed, because the hyperlink that has been clicked no longer has the hover and active style. The solution is to change the order of CSS properties :L-V-H-A:

    a:link {} 
    a:visited {} 
    a:hover {} 
    a:active {}
    Copy the code
  7. In IE,even has x,y properties, but no pageX,pageY properties;

    In Firefox, the event object has pageX and pageY properties, but no x and y properties.

    Solution :(conditional comments) the disadvantage is that it may increase the number of additional HTTP requests in Internet explorer.

  8. Png24 bit image appears in the background of iE6 browser, the solution is to make PNG8.

14. Write solutions to several IE6 bugs

1. Use of display caused by bilateral distance BUG float

2. 3 Pixel problems using float caused by using Dislpay: inline-3px

3. Use the correct writing order link visited hover active

4. Add position:relative to parent for Ie Z-index problem

5. Png transparent using JS code change

6. Min-height! Important solution ‘

7. Select using iframe nesting in IE6

8. Why is there no way to define the width of the container around 1px (IE6 default line height, use over:hidden,zoom:0.08 line-height:1px)

9. Ie 6 is not supported! important

15. Why initialize CSS styles

Because of browser compatibility issues, different browsers have different default values for some tags, and if the CSS is not initialized, the page will display differently from browser to browser. Of course, initializing a style will have an impact on SEO, but you can’t have your cake and eat it, but try to initialize with minimal impact.

16. What is the difference between the calculation method of absolute containing block and normal flow?

In either case, we must first find the element in its ancestor whose nearest position is not static and then determine:

  1. If the element is inline, then containing block is the smallest rectangle that can contain the first and last inline box padding box generated by the element.
  2. Otherwise, it consists of the padding box of this ancestor element.

Initial containing block: initial containing block: initial containing block

Supplement:

1. Static (default)/relative: the content box of its parent element (i.e. without the padding)

2. Absolute: Look up the nearest element with the position absolute/relative

3. Fixed: Its containing block is always the root element (HTML /body), and the root element is also initial containing block

17. The collapse property in CSS has a value for visibility. What’s the difference between different browsers?

When an element’s **visibility** property is set to **collapse**, it behaves the same as **hidden** for normal elements. The exception is that if the element is related to the table, such as table row, table group, table column, table column group, it will behave the same as **display: None **.

In Chrome, there is no difference between using **collapse values and **hidden values.

In Firefox, Opera, and IE11, using the **collapse value works exactly as it is: the row of the table disappears and the row below it replaces it.

18. Display: None and visibility:hidden what is the difference?

Display: None hides the corresponding element and allocates no more space in the document layout (reflux + redraw)

Visibility :hide the corresponding element and leave the original space in the document layout (redraw).

With the CSS display: None attribute, the width, height, and other attributes of an HTML element are “lost”; Using the visibility:hidden property, the HTML element (object) is only visually invisible (fully transparent), and the space it occupies remains.

19. What happens when position is superimposed on display, overflow, float?

The display attribute specifies the type of box that the element should generate; The position attribute specifies the positioning type of the element; The float property is a layout that defines the direction in which elements float. Similar to the priority mechanism: position: Absolute /fixed has the highest priority, float does not work when they are present and display values need to be adjusted. Elements located by float or Absolute can only be block elements or tables.

20. Why does the float occur? When do YOU need to clear a float? What are the ways to clear a float? What are the pros and cons? Which one do you think is the best? Why is that?

Reasons for floating:

The floating element stops when it touches the border that contains it or the border of the floating element. In the CSS specification, float positioning is not part of the normal page flow, but is positioned independently, so the block box of the document flow acts as if the float box does not exist. Floating elements float on the block box of the document flow.

Position: Fixed is a subclass of position: Absolute. The floating box can be moved left and right until its outer edge encounters the edge of the containing box or another floating box, so floating positioning is not part of normal page flow. The normal flow in the document will behave as if the float box does not exist. When the float box height exceeds the contain box, the contain box will not automatically scale the height of the pen box float element. Therefore, a parent container containing only floating elements is displayed without considering the placement of the child elements, causing the parent container to appear empty.

Problems with floating:

  1. The height of a parent element cannot be stretched, affecting elements of the parent’s level
  2. Non-floating elements (inline elements) that are siblings of the floating element follow
  3. If the first element does not float, then the elements before it need to float as well, otherwise the structure of the page display will be affected.

How to clear the float:

  1. The parent div defines height
  2. The last floating element is followed by an empty div tag and the style clear:both. (Theoretically, you can remove any tags and add meaningless ones)
  3. The parent tag containing the floating element adds the style overflow to hidden or auto.
  4. Parent div defines zoom (empty tag elements clear float and have to add meaningless code, use zoom:1 for IE compatibility)
  5. Clear float with after pseudo-element (for non-IE)

1**, parent div define height**

Principle: If the parent div manually defines its height, it solves the problem that the parent div cannot automatically obtain its height

Pros: Simple, little code, easy to learn

Disadvantages: Only suitable for layouts with fixed height, giving an exact height can cause problems if the height is different from the parent div

Suggestion: This parameter is not recommended. This parameter is recommended only for layouts with fixed height

2**, end with empty div tag clear:both**

Principle: Add an empty DIV, use CSS to improve clear:both clear floating, so that the parent div can automatically get to the height

Pros: Simple, less code, good browser support, less prone to weird problems

Disadvantages: many beginners do not understand the principle; If you have a lot of floating layouts, you have to add a lot of empty divs, which makes you feel uncomfortable

Suggestion: This method is not recommended, but it is the main method used to clear the float

3**, parent div definition overflow:hidden**

How it works: Width or zoom:1 must be defined, and height cannot be defined. When using overflow:hidden, the browser automatically checks the height of the float area

Pros: Simple, less code, good browser support

Disadvantages: Cannot be used with position, as excess sizes are hidden

Suggestion: Only recommended for those who do not use position or who have a deep understanding of overflow:hidden

4**, parent div defines pseudo-classes :after and zoom**

Principle: IE8 above and non-IE browser support :after, principle and method 2 is a bit similar, ZOOM (IE to have properties) can solve IE6, IE7 floating problem

Advantages: good browser support, not prone to strange problems (currently: large websites are used, such as: Teng Xun, netease, Sina, etc.)

Shortcomings: code, many beginners do not understand the principle, to use the combination of two sentences of code, to make mainstream browser support

Suggestion: It is recommended that you define public classes to reduce CSS code

Div {clear:both; div{clear:both; }

(2) the parent element of {overflow: hidden | auto; zoom:1}

(3) : After pseudo-selector that automatically creates a child element at the end of the parent container

.clearfix:after { content: "\0020"; display: block; height: 0; clear: both; } .clearfix { zoom: 1; }Copy the code

“Clearfix” is the class name of the parent container, “content:”020″;” Is to put a blank at the end of the parent container,

“height: 0;” Is to make this this whitespace character not show up, “display: block; clear: both;” Is to ensure that the whitespace character is a non-floating independent block. :after selector not supported by IE 6, add an IE 6 unique command “zoom:1;” Will do.

21. Margin overlap

Wrap a container around the overlapping element and trigger the container to generate a BFC. Example:

<div class="aside"></div> <div class="text"> <div class="main"></div> </div> <! -->.aside {margin-bottom: 100px; width: 100px; height: 150px; background: #f66; } .main { margin-top: 100px; height: 200px; background: #fcc; }.text{/* Block margin from overlapping */ overflow: hidden; /* block margin from overlapping */ overflow: hidden; // The BFC attribute has been triggered. }Copy the code

22. What is the display value of the element after the float is set?

Automatically change to display:block

23. Have you used media queries for the mobile layout?

By querying the media, you can define different CSS for different sizes and sizes of media to adapt to the corresponding device display.

  1. The inside
    <link rel="stylesheet" type="text/css" href="xxx.css" media="only screen and (max-device-width:480px)">
    Copy the code
  2. CSS :

  3. @media only screen and (max-device-width:480px) {/ CSS style /}

24. What is a CSS preprocessor/post-processor? Why do people use them?

Preprocessor such as LESS, Sass, Stylus, used to precompile Sass or LESS, enhance the reuse of CSS code, hierarchy, mixin, variables, loops, functions, etc., with a very convenient UI component modular development ability, greatly improve work efficiency.

Postprocessors, such as PostCSS, are generally seen as treating CSS according to the CSS specification in a completed stylesheet to make it more efficient; By far the most common approach is to add browser private prefixes to CSS properties to address cross-browser compatibility issues.

The CSS preprocessor adds some programming features to CSS without having to worry about browser compatibility. For example, you can use variables in CSS, simple logic programs, functions (such as the variable $color in the code editor on the right), and other basic programming language features. Make your CSS cleaner, more adaptable, more readable, easier to maintain, and more.

Other CSS preprocessor languages:

  • Sass (SCSS)
  • LESS
  • Stylus
  • Turbine
  • Swithch CSS
  • CSS Cacheer
  • DT CSS

Why use them?

The structure is clear and easy to expand.

You can easily mask browser-private syntax differences. Needless to say, this encapsulates the repetitive processing of browser syntax differences and reduces meaningless mechanical labor.

Multiple inheritance can be easily implemented.

Fully compatible with CSS code, which can be easily applied to older projects. LESS simply extends the CSS syntax, so older CSS code can be compiled with LESS code.

25. What are the ways to optimize the CSS and improve its performance?

  1. Avoid excessive restraint

  2. Avoid descendant selectors

  3. Avoid chained selectors

  4. Use compact syntax

  5. Avoid unnecessary namespaces

  6. Avoid unnecessary repetition

  7. It is best to use semantic names. A good class name is one that describes what it is rather than what it looks like. Right

  8. Avoid!!! Important, you can select other selectors

  9. As simple as possible, you can combine duplicate rules from different classes

  10. Fixed parsing errors

  11. Avoid using multi-class selectors

  12. Remove an empty CSS rule

  13. Use the display property correctly: Certain style combinations are invalid due to display, increasing the size of the style and affecting parsing performance.

Display: Inline should not be used after width, height, margin, padding, and float. Display: float should not be used after inline-block. Display :block should not be used vertical-align. Display :table-* < display:table-* < display:table-* >Copy the code
  1. Don’t overuse floats: While floats are inevitable, there is no denying that many CSS bugs are caused by floats.
  2. Don’t abuse web fonts
Web Fonts may be unfamiliar to Chinese websites, but they are very popular abroad. Web Fonts are often bulky, and some browsers block page rendering damage when downloading Web Fonts.Copy the code
  1. Don’t have too many font-size declarations: This is a design issue, and well-designed pages don’t have too many font-size declarations.

  2. Do not use ID identifiers in selectors, mainly because of style reuse and coupling to the page.

  3. Do not define too many styles for the H1 ~ H6 elements

  4. The heading element can be defined uniformly throughout the site. If additional custom styles are needed, other selectors can be used instead.

  5. Do not repeat the h1 to H6 elements

  6. A value of 0 does not require any units

  7. Standardize the various browser prefixes: Usually put the browser prefix first and the standard style attributes last, like:.foo{

       -moz-border-radius: 5px;
       border-radius: 5px; 
    Copy the code

    }

  8. To use advanced features such as CSS gradient, you need to specify prefixes for all browsers

  9. Avoid making selectors look like regular expressions

  10. CSS3 adds some complex attributes such as ~=, which are not supported by all browsers. Use with caution.

  11. Beware of broken Box Models

26. How do browsers parse CSS selectors?

CSS selectors are parsed from right to left to avoid traversing all elements. If you match from left to right, you find that you don’t match the rules, and you need to backtrack, and you lose a lot of performance. If matching from right to left, all the rightmost nodes are found first, and for each node, the branch traversal is ended by looking up for its parent node until the root element or matching rule that meets the condition is found. The performance of the two matching rules is very different because the right-to-left matching rule filters out a large number of the right-most nodes (leaf nodes) that do not meet the criteria in the first step, while the left-to-right matching rule’s performance is wasted on failed lookups. After CSS parsing is completed, it is necessary to analyze the result of parsing and the content of DOM Tree together to build a Render Tree, which is finally used for drawing. When establishing the Render Tree (the “Attachment” process in WebKit), the browser will determine what kind of Render Tree is generated for each DOM Tree element according to the CSS parsing results (Style Rules).

27. Should I use odd or even fonts on a web page? Why is that?

Use even-numbered fonts. Even font size is relatively easy to scale with the rest of the Web design. Windows’s built-in dot-matrix (Dot-matrix) only provides dot-matrix sizes of 12, 14, and 16 pixels starting with Vista, whereas 13, 15, and 17 pixels are smaller. (that is, each word takes up 1px more space, but the lattice remains the same), so it is slightly thinner.

28. Which scenarios are margin and padding suitable for?

◆ When to use margin

When you need to add white space outside the border.

When a background is not required in the margin.

The space between two boxes connected above and below is needed to cancel each other out. If margin is 15px+20px, you will get 20px blank.

◆ When to use padding

Need to add white space in border internal test.

When a background (color) is needed in the margin.

The space between two boxes that are connected, hopefully equal to the sum of them. If you add 15px+20px padding, you’ll get 35px of space.

The browser is incompatible

In IE5.x and IE6, when you specify margin for the float box, the left margin may become twice the width. This can be resolved by using padding or by specifying the box as display:inline.

29. Is the percentage of the element’s portrait set relative to the container’s height?

When the width of an element is set as a percentage, it is calculated relative to the width of the parent container. However, for some vertical distance properties such as padding-top, padding-bottom, margin-top, margin-bottom, etc., When they are set as a percentage, they are also based on the width of the parent container, not the height.

30. How does full-screen scrolling work? What properties of CSS are used?

  1. Principle: It is similar to the rotation, the whole elements are arranged all the time. Suppose there are 5 full-screen pages to be displayed, then the height is 500%, and only 100% is displayed. The rest can be positioned on the Y-axis by transforming or by using margin-top
  2. Overflow: hidden; Transition: all 1000ms ease;

31. What is responsive design? What is the rationale behind responsive design? How to compatible with lower versions of IE?

Responsive Web design is the ability for a website to be compatible with multiple terminals, rather than making a specific version for each terminal.

The basic principle is to detect different device screen sizes through media queries.

The page header must have a meta declared viewport.

<meta name= 'viewport' content= "width=device-width, initial scale=1\.maximum-scale =1, user-Scalable =no" >Copy the code

32. Parallax scrolling?

Parallax Scrolling creates stunning 3D effects by manipulating the background to move slower than the foreground as you scroll down a web page.

  1. CSS3 implementation advantages: short development time, performance and development efficiency is better, the disadvantage is that it is not compatible with the lower version of the browser
  2. JQuery controls the scrolling speed of different layers, calculates the time of each layer, and controls the scrolling effect. Advantages: can be compatible to each version, the effect of controllable good disadvantages: development up to the producer of high requirements
  3. Parallax-scrolling is a parallax-scrolling method

33. What’s the difference between double colons and single colons in before and after? Explain what these two pseudo-elements do

  1. The single colon (:) is used for CSS3 pseudo-classes, and the double colon (::) is used for CSS3 pseudo-elements.
  2. Before is a pseudo-element defined before the body of the element in the presence of a child element. It doesn’t exist in the DOM, it only exists in the page.

The :before and :after pseudo-elements are new in CSS2.1. Originally, pseudo-elements were prefixed using a single colon syntax, but as the Web evolved, in the CSS3 specification, the syntax of pseudo-elements was modified to use double colons, becoming ::before ::after

Note: Only single colon notation is supported for IE6/7/8, while modern browsers support both notations. In addition, the single and double colon areas in CSS3 are mainly used to distinguish pseudo-classes and pseudo-elements.

34. What do you mean by “line-height”?

Line height is the height of a line of text, specifically the distance between the baseline of two lines of text. In CSS, the height function is the height and line-height, there is no definition of the height attribute, the final effect of its performance must be line-height. Vertical center of a single line of text: To center a single line of text vertically, set the word-height value to a value equal to the height. You can also delete the height. Multiple lines of text are vertically centered: Set the display property to inline-block.

35. How to get Chrome to support text less than 12px?

p{ font-size:10px; - its - transform: scale (0.8); //0.8 is the scale}Copy the code

36. Make the fonts on the page sharper and thinner.

E. Webkit-font-smoothing: smoothing doesn’t work on Windows, but it does on IOS devices.

37. position:fixed; How to deal with invalid in Android?

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
Copy the code

38. If you need to manually write an animation, what do you think is the minimum time interval and why?

The default frequency of most monitors is 60Hz, or 60 refreshes per second, so the theoretical minimum interval is 1/60 * 1000ms = 16.7ms.

39. What causes the invisible gap between Li and Li? What’s the solution?

The arrangement of the line box is affected by the space in the middle (carriage return space), etc., because the space is also a character, and the space is also styled and takes up space, so there is a space. If you set the character size to 0, there is no space. Solution:

  1. Can be
  2. The code is all in one row
  3. Float: left in float LI
  4. Mso-font-weight: 0pt; mso-font-weight: 0pt; mso-font-weight: 0pt;
  5. Ul {letter-spacing: -4px; }; li{letter-spacing: normal; }

40. Display :inline-block when will the gap be displayed?

  1. When there is space, there will be a gap solution: s in addition to space
  2. Resolve when margin is positive: use negative value
  3. Word-spacing :0; letter-spacing :0; word-spacing :0

41. Have a highly adaptive div with two divs inside, one 100px high, and hopefully the other will fill the remaining height

The outer div uses position: relative; Highly adaptive divs use position: Absolute; top: 100px; bottom: 0; left: 0

42. PNG, JPG, GIF, these image formats explain, respectively when to use. Have you read about WebP?

  1. PNG is a bitmap file format for lossless data compression. The advantages are: high compression ratio, good color. You can use it in most places.
  2. JPG is a distortion compression method used for photos. It is a destructive compression method. It does a good job of smoothing changes in tone and color. On the WWW, a format used to store and transfer photos.
  3. GIF is a bitmap file format that reproduces true color images in 8 bit colors. You can animate it.
  4. Webp, Google’s image format launched in 2010, is only two-thirds as compressed as JPG and 45 percent smaller than PNG. The downside is that it takes longer to compress, and compatibility is poor, currently supported by Google and Opera.

43. What is the difference between the style tag after the body and before the body?

The page loads from top to bottom, of course, loading the style first. Since the browser parses the HTML document line by line, parsing to a style sheet written at the end (either outside or in the style tag) causes the browser to stop rendering and wait until it loads and the parsing style sheet is complete. FOUC phenomenon (i.e. page flicker caused by style failure) may occur in Windows IE.

44. The CSS property overflow property defines what happens to the content of the overflow element content area.

When the parameter is scroll, you have to have a scroll bar. When the parameter is auto, the scroll bar appears when the child element content is greater than the parent element. When the argument is visible, the overflow appears outside the parent element. When the parameter is hidden, overflow is hidden.

45. What are CSS Sprites? What are its strengths and weaknesses?

CSS Sprites small image background sharing technology. It combines a bunch of small pictures into a big one. Then use the combination of background-image, background-repeat and background-position of CSS for background positioning. The use of CSS Sprites can be very good to reduce the HTTP page request, thus greatly improve the performance of the page; CSS Sprites reduce the number of bytes in an image.

Advantage:

1. Very good to reduce the page request, greatly improve the performance of the page;

2. Reduce the number of bytes in the picture;

3. Solved the problem of web designers on image naming;

4. Easy to replace and maintain.

Disadvantage:

1. Sufficient space should be reserved when merging images, as background fracture is easy to occur under widescreen and high-resolution screens;

2. The development is troublesome and the measurement is tedious; (Style generator available)

3. Maintenance trouble, a few changes to the background may affect the whole image, making bytes increase and changing the CSS.

46. What is the difference between CSS pseudo-classes and pseudo-elements?

First answer:

Pseudo classes: :focus, :hover, :active

Pseudo-elements: :before, :after

Pseudo-classes are essentially designed to make up for the lack of regular CSS selectors in order to get more information;

Pseudo-elements essentially create a virtual container with content;

The syntax of pseudo-classes and pseudo-elements in CSS3 is different;

Multiple pseudo-classes can be used simultaneously, but only one pseudo-element can be used simultaneously.

Second answer:

Pseudo-classes: Pseudo-classes select elements based on the current state of the element, or the current properties of the element, rather than static markers such as the element id, class, or attribute. Since states change dynamically, when an element reaches a particular state, it may get a pseudo-class style; When the state changes, it loses this style again. As you can see, its functionality is somewhat similar to class, but it is based on abstractions outside of the document, hence the name pseudo-class.

`:first-child    :link:    :visitive    :hover    :active    :focus   :lang`

Pseudo-elements: Unlike pseudo-classes for special-state elements, pseudo-elements operate on specific elements at a deeper level than pseudo-classes and are therefore much less dynamic than pseudo-classes. In fact, pseudo-elements are designed to select the first word (female), the first line of an element’s content, and before or after some content that ordinary selectors cannot do. The content it controls is actually the same as the element, but it itself is an abstraction based on the element and does not exist in the document, so it is called a pseudo-element.

:first-line 
:first-letter 
:before 
:after
Copy the code

47. Is there any way to style a DOM with its CSS?

External style sheet, introduces an external CSS file

An internal style sheet that places CSS code inside the tag

Inline styles, which define CSS styles directly inside HTML elements

48. What properties can be defined in CSS to keep a DOM element from being visible to the browser?

** Set the display property to None, or set the visibility property to hidden

** Set the width and height to 0, the transparency to 0, and the z-index position to -1000

49. What is a Css Hack? What are the hacks of IE6,7 and 8?

Answer: A CSS Hack is a way to solve the problem of how different browsers interpret CSS and how different browsers create different CSS styles.

50. What is the specific difference between an inline element and a block-level element? Can the padding and margin of the inline elements be set?

Block level element (block) properties:

Always an exclusive row, appearing to start on a different line, and the following elements must also be displayed on a different line;

Width, height, padding, and margin can all be controlled.

Inline elements feature:

On the same line as the adjacent inline element;

Width, height, top/bottom(padding-top/padding-bottom), and top/bottom(margin-top/margin-bottom) are all immutable (i.e., the padding) Left and right of margin are configurable).

The browser also has default inline-block elements (which have built-in dimensions, width and height, but don’t wrap). What do they have?

The answer:,,,.

Related articlesWhy can I set width and height for inline elements such as IMG and input

51. What is margin overlap? What’s the result of the overlap?

Margin-collapse.

In CSS, the margins of two adjacent boxes can be combined into a single margin. This way of merging margins is called folding, and the resulting margins are called folded margins.

The folding results follow the following calculation rules:

  1. When two adjacent margins are both positive, the fold results in the larger value between them.
  2. When two adjacent margins are both negative, the fold results in a larger value of the absolute value of both.
  3. When the margins are one plus one minus, the fold is the sum of the two.

52. What is the difference between rgba() and opacity?

Both rgba() and Opacity can be achieved, but the biggest difference between opacity and opacity is the opacity of all contents within an element.

Rgba () only works on the color of an element or its background color. (Children of elements that make RGBA transparent do not inherit the transparency effect!)

53. What are two properties in CSS that allow text to overlap vertically and horizontally?

Vertical direction: line-height

Horizontal: letter-spacing (the letter-spacing attribute increases or decreases the space between characters)

So the question is, what are some useful uses for letter-spacing?

Answer: Can be used to eliminate the issue of newline spacing between inline-block elements.

54. The difference between px and EM.

Px and EM are both units of length. The difference is that the value of px is fixed, and it is easy to calculate. The value of em is not fixed, and EM inherits the font size of the parent element.

The browser default font height is 16px. So unadjusted browsers will fit: 1em=16px. So 12px=0.75em, 10px=0.625em.

Describe a “reset” CSS file and how to use it. What about normalize.css? Do you understand their differences?

Different browsers have different default styles for some elements, and if not handled, there are necessary risks in different browsers.

You might use Normalize instead of your reset style file. It does not reset all style styles, but only provides a reasonable set of default style values. It’s consistent and reasonable across multiple browsers, but it doesn’t disturb everything else (like bold headlines).

Q: Does the translate() method move an element on the z-axis?

Can’t. It can only move the x and y axes. Translate3d can.

57. What are the new features of CSS3?

1. CSS3 achieves rounded corners (border-RADIUS), shadow (box-shadow),

2. Add text-shadow, linear gradient and transform to the text.

Rotate (9deg) scale(0.85,0.90) translate(0px,-30px) skew(-9deg,0deg); // Rotate, scale, position, tilt

4. Added more CSS selectors for multiple backgrounds rGBA

5. The only pseudo-element introduced in CSS3 is :: Selection.

6. Media query, multi-column layout

7. border-image

58. What’s the difference between XHTML and HTML

Functional differences: HTML is a basic WEB page design language; XHTML is an XML-based markup language that is compatible with browsers, mobile phones, and PDAs, and browsers can quickly and correctly compile web pages.

In writing custom:

(1) All XHTML tags must be lowercase

(2) XHTML tags must be paired

(3) The order of XHTML tags must be correct

(4) All XHTML attributes must be in double quotes

1) Target = “_blank”

(6) XHTML documents must have a root element.

(7) XHTML elements must be properly nested.

59. What are the three layers of the front page?

Structure layer Html presentation layer CSS behavior layer JS

60. What are the basic statements of CSS?

Selector {attribute 1: value 1; Attribute 2: Value 2; … }

61. Compared to HTML4, what elements are discarded by HTML5?

Discarded elements include:

Frame,

Frameset,

“Noframe

The applet,

The big,

Center,

· basefront

62. What are the ways to introduce CSS? What’s the difference between using Link and @import?

Answer: inline, inline, outside chain, import

(1) Link belongs to XHTML tag. In addition to loading CSS, it can also be used to define RSS, rel connection attributes and other functions. It is incompatible and supports using javascript to change the style. @import is provided by CSS and can only be used to load CSS. It does not support using javascript to change styles.

(2) When the page is loaded, the link will be loaded at the same time, while the CSS referenced by @import will wait until the page is loaded.

(3) Import is proposed by CSS2.1, which is not supported by browsers below CSS2.1, and can only be recognized in IE5 or above, while link is XHTML tag, so there is no compatibility problem.

Describe your understanding of the browser kernel

It is divided into two parts: Layout Engineer or Rendering Engine and JS Engine.

(1) Rendering engine: responsible for obtaining the content of the web page (HTML, XML, images, etc.), organizing information (such as adding CSS, etc.), and computing the display mode of the web page, and then output to the monitor or printer. The kernel of a browser interprets the syntax of a web page differently, and therefore renders it differently. All web browsers, E-mail clients, and other applications it needs to edit and display the web require the kernel.

(2) JS engine: parse and execute JavaScript to achieve the dynamic effect of web pages;

At first there was no clear distinction between the rendering engine and JS, but as JS engines became more and more independent, the kernel tended to just render the engine.

64. What are some common browser kernels?

**Trident kernel ** : IE,MaxThon,TT,The World,360, Sogou, etc. [also known as MSHTML]

Gecko kernel * * * * : Netscape6 and above version, FF, MozillaSuite/SeaMonkey, etc.

**Presto kernel ** : Opera7 and above. [Opera kernel was Presto, now Blink;]

**Webkit kernel ** : Safari,Chrome, etc. [Chrome: Blink (WebKit branch)]

**EdgeHTML kernel ** : Microsoft Edge. [This kernel is actually derived from MSHTML fork, which removes almost all of IE’s private features]

65. Understanding of WEB standards and W3C

Closing tags, labels lowercase, not disorderly nested, increases the chances of a search robots, using CSS and js scripts outside the chain, the structure behavior of separation, with the page file download faster, content, content can be accessed by more users can be accessed by a wider range of equipment, less code and components, easy to maintain, easy to change, No need to change the page content, provide a printed version instead of copying the content, improve the usability of the site;

66. Why don’t we need a Document Type Definition in HTML5?

HTML5 doesn’t use SGML or XHTML, it’s a brand new thing, so you don’t need to refer to a DTD. For HTML5, you just place the following document type code to tell the browser to recognize it as an HTML5 document

67. Will HTML5 work if I don’t put it in?

No, the browser will not recognize it as an HTML document, and the HTML5 tags will not work properly

68. What is a datalist in HTML5?

The Datalist element in HTML5 helps provide text box autocomplete, as shown below:

69. What is the use of column layout in CSS?

CSS column layout helps you split text into columns. For example, consider the following magazine story in a large text, but we need to divide them into 3 columns using boundaries. Here, HTML5 column layout helps

70. How to center a background image horizontally and vertically

Set the background – position: center;

SRC = “SRC”; SRC = “SRC”; SRC = “SRC”; SRC = “SRC”

Let one font be identified as italic, or use italic if that format is not available

72. How to understand inheritance and reuse of CSS?

Inheritance: After an attribute is applied to a particular tag, the attribute should also be applied to the child tags of that tag. This act is called inheritance. But not all properties are inherited. As the text style is generally inherited, the width and height of the box diagram is generally not inherited, in short, the inheritance will be inherited, should not be inherited are not inherited.

Reuse: A style file that can be used on multiple pages is useful for some common style refactoring.

73. How do you manage all the CSS files,js and images on a large, heavily visited website?

Answer: It involves manpower, division of labor, synchronization

(1) The advance team must determine the global style, coding pattern, etc

(2) Writing habits must be consistent

(3) Annotate the style writer, and timely annotate each module (annotate the key style invocation place)

(4) Page annotation

(5) Css and HTML folder parallel storage, naming should be unified

(6) Js sub-folder storage, named with the Js function shall prevail in English translation

(7) The picture adopts the integrated. PNG format file, try to integrate together, convenient management in the future.

74. What is CSS for forcing newlines?

Word-break:break-all;

(HTML and CSS)

1. The role of brief.

The declaration is at the front of the document, before the tag.

It is not an HTML tag, it is used to tell (declare) the Web browser which version of HTML is used for the page

2. What is the difference between inline elements and block-level elements? 

Inline elements:

(1) The elements in the line do not break

(2) You cannot set the size of an element within a row

(3) The size of inline elements is determined by the content

Block elements:

(1) Block elements form separate lines

(2) Block elements can be set to size

(3) If the width of block element is not set, the width will adapt to the width of its parent

3. List common inline elements and block elements and explain their functions

Line elements:

Span, img, a, lable, input, abbr, em, big, cite, I, q, textarea, select, small, sub, sup, Strong, U (underline), button (default display: inline-block)

From the browser display results, we can see that the adjacent inline elements do not break the line, the width is the width of the content, the padding of the four directions are valid (from the span tag we can see that for the inline elements, the row height is not affected, and the parent element is not stretched; Margin is valid only in the horizontal direction (where vertical margin is valid for inline replacement elements (such as IMG elements), but not for inline non-replacement elements). Width and height attributes cannot be set. Inline block elements behave just like inline elements except that they can be set with width and height attributes.

Block elements:

Div, p, H1-H6, ul, ol, dl, li, dd, table, hr, blockquote, address, table, menu, pre, HTML5 added header, section, aside, footer, etc

From the browser display results, it can be seen that the block-level element opens a new row (even if the width attribute is set, it will be an exclusive row), and it can be used to cover the width of the parent element as much as possible. The width and height attributes can be set. The default display attribute of the table element browser is table.

4. Two ways to center inline elements horizontally

(1) Find the corresponding label parent, set the parent text align: center;

Margin: 0 auto; (2) Convert element to block element; set margin: 0 auto;

5. How to achieve a title text center? text-align : center

6. Make block elements appear on one line. float : left

7. Make the text bold and tilt the text

Bold:

**CSS: ** weight: bold

HTML:

Italics:

CSS: the font – style: italic | oblique, the font – style: normal (normal font)

HTML:

✳8. Fix the img image margin problem

Google explains it like this:

The gap at the bottom of the image actually refers to the layout model of the elements within the line. The default vertical alignment of the image is the baseline, and the position of the baseline is related to the font. So at some point, the gap at the bottom of the image might be 2px, and at other times it might be 4px or more. Different font sizes should also affect the size of the gap.

The solution:

The best solution is to define vertical-align. Note: in IE6, when defining vertical-align as middle, there is about one pixel of top margin, preferably top or bottom. Font :0; font-size:0

(1) Convert to (row-level) block elements

 display : block
Copy the code

(2) Floating, floating elements can be converted to block elements by default (you can set the width and height attribute at will)

Float: left;Copy the code

(3) define vertical-align for img (eliminate bottom margin)

img{    
    border: 0;    
    vertical-align: bottom;
}
Copy the code

(4) Set font size to 0;

(5) Set the parent label to the same height as the picture

9. What might happen if float elements are not side-by-side?

The parent level is not wide enough so that elements cannot be displayed side by side;

10. How to set the CSS?

Inline styles, internal styles (write a style), and external styles

11. What properties are used to represent CSS inner and outer margins?

padding margin
Copy the code

12. Clear all default margins.

padding : 0;
margin : 0;
Copy the code

13. Which attribute of word spacing and letter spacing should Chinese use?

Word – spacing: words

Letter-spacing: indicates letters and Chinese characters

14. How to underline, underline, and delete text

text-decoration : underline | overline | line-through

15. Clear the list symbols and change the background to pictures

list-style:none;
background-image:url()
Copy the code

16. What are the basic properties of boder?

Width (width)

(Color)

The past five years have seen a steady growth in the country’s growth rate, which has seen a steady growth in the country’s growth rate

17. How do row elements become block elements, or row-level block elements, and what are the characteristics of row-level block elements

Diaplay: block | inline – block

18. What is the difference between the title attribute and the Alt attribute on the tag?

Title: the prompt text when the mouse is placed,

Alt: A message is displayed when the image path fails

19. How to prevent garbled characters?