Home Web Front-end JS Tutorial 2018 latest front-end interview questions 11

2018 latest front-end interview questions 11

Mar 07, 2018 pm 02:37 PM
test questions

This time we bring you the latest front-end interview questions in 2018. We know that interviews are an essential part of front-end work. This time, the common front-end interview questions are sorted and summarized to help you get through the front-end interview. Big trouble. Let’s take a look.

[Related recommendations: Front-end interview questions (2020)]

1. Describe how z-index and overlay context are formed.

First let’s look at the reasons for the formation of overlay context in CSS:

1. Negative margin When the margin is a negative value, the element will be offset outward according to the reference line. margin-left/The reference line of margin-top is the element on the left/the element above (if there is no sibling element, it is the left inner/upper inner side of the parent element), margin-right The reference line with margin-bottom is the right side of the border/the lower side of the border of the element itself. Generally, negative margins can be used for layout, but if not calculated properly, elements may overlap. The stacking order is determined by the position of the elements in the document, with elements appearing later on top.

2. Relative/absolute/fixed positioning of position When the position value is set to relative/absolute/fixed for an element, the offset of the element may overlap, and the z-index attribute is activated. The z-index value can control the stacking order of positioned elements in the direction perpendicular to the display screen (Z axis). When elements with a large value overlap, they will be on top of elements with a small value.

z-index attribute z-index is only valid on elements whose position attribute value is relative, absolute, or fixed.

Basic principle: The z-index value can control the stacking order (stack order) of positioned elements in the direction perpendicular to the display screen (Z axis). When elements with a large value overlap, they will be on top of elements with a small value. .

Use relativity: The z-index value only determines the stacking order of sibling child elements in the same parent element. The z-index value of the parent element (if any) defines the stacking order for the child elements (the CSS version of stacking "Pin Dad").

If the parent element containing the z-index value cannot be found when tracing upward, it can be regarded as a free z-index element. It can position the element with the sibling brothers of the parent element or other free positions. Elements are compared with their z-index values ​​to determine their stacking order. If the z-index values ​​of sibling elements are the same, the stacking order is determined by the position of the elements in the document, with the elements appearing later being on top. So if you find that an element with a larger z-index value is obscured by an element with a smaller value, please first check the relationship between the dom nodes between them. It is probably because its parent node has activation and z-index set. The position of the value positions the element.

2. Please describe BFC (Block Formatting Context) and how it works.

BFC (Block Formatting Context) literally translates as "block-level formatting range".

3. List different techniques for clearing floating , and point out their applicable usage scenarios.

First of all, let’s explain why we need to clear floats? When all the elements in a container are floated, since floating will separate the elements from the ordinary document flow, there will be no content to hold it open for the outer container. The background settings cannot be displayed, and the margin settings cannot be displayed. Method of clearing floats:

1. Add new elements and apply clear: both;

例如: <div class="outer"> <div class="div1">1</div> <div class="div2">2</div> <div class="div3">3</div> <div class="clear"></div> </div>
.clear{clear:both; height: 0; line-height: 0; font-size: 0}
Copy after login

Advantages: simple, less code, good browser support, not prone to strange problems. Disadvantages are: A lot of invalid layouts are added, but this is a more commonly used method to clear floats.

2. Parent div definition overflow: auto or hidden

//这里添加了一个class <div class="div1">1</div> <div class="div2">2</div> <div class="div3">3</div> </div>
.over-flow{ overflow: auto; zoom: 1; //zoom: 1; 是在处理兼容性问题 }
Copy after login

Principle: width or zoom: 1 must be defined, but cannot be defined at the same time height, use the overflow attribute to clear floats. One thing to note is that the overflow attribute has three attribute values: hidden, auto, and visible. We can use hidden and auto values ​​to clear floats, but remember not to use visible values. If this value is used, the effect of clearing floats will not be achieved.

Advantages: Simple, less code, good browser support Disadvantages: When using auto, when the internal width and height exceed the parent div, a scroll bar will appear, and when using hidden, it will be hidden

3. Principle of the after method: Use :after and :before to insert two element blocks inside element to achieve the effect of clearing floats. The implementation principle is similar to the clear:both method, except that:clear inserts a div.clear tag in HTML, while this method uses its pseudo-class clear:after to add an effect similar to div.clear inside the element.

Let’s take a look at its specific usage:

<div class="outer"> <div class="div1">1</div> <div class="div2">2</div> <div class="div3">3</div> </div>
.outer {zoom:1;} /==for IE6/7 Maxthon2==/ .outer :after {clear:both;content:’.’;display:block;width: 0;height: 0;visibility:hidden;}
Copy after login

where clear:both; refers to clearing all floats; content: '.'; display:block; for FF/chrome/opera/ IE8 cannot be missing, in which content() can have a value or be empty. The function of visibility:hidden; is to allow the browser to render it but not display it, so that the float can be cleared. So in general, it is recommended to use pseudo-class method.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

2018 latest front-end interview questions ten

2018 latest front-end interview questions nine

2018 latest front-end interview questions eight

The above is the detailed content of 2018 latest front-end interview questions 11. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I create and publish my own JavaScript libraries? How do I create and publish my own JavaScript libraries? Mar 18, 2025 pm 03:12 PM

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

How do I optimize JavaScript code for performance in the browser? How do I optimize JavaScript code for performance in the browser? Mar 18, 2025 pm 03:14 PM

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

How do I debug JavaScript code effectively using browser developer tools? How do I debug JavaScript code effectively using browser developer tools? Mar 18, 2025 pm 03:16 PM

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How do I use source maps to debug minified JavaScript code? How do I use source maps to debug minified JavaScript code? Mar 18, 2025 pm 03:17 PM

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts Mar 15, 2025 am 09:19 AM

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

The difference in console.log output result: Why are the two calls different? The difference in console.log output result: Why are the two calls different? Apr 04, 2025 pm 05:12 PM

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

See all articles