Home  >  Article  >  Web Front-end  >  Classic CSS interview questions

Classic CSS interview questions

coldplay.xixi
coldplay.xixiforward
2020-08-03 15:18:424100browse

Classic CSS interview questions

#1. What is the difference between the standard box model and the lower version IE box model (weird mode)?

Standard box model: content width (content) border padding margin;

IE low version box model: content width (content border padding) margin;

The main difference is the width of the box model;

  • The box-sizing attribute is used to control the parsing mode of the element's box model. The default is content-box

  • content-box: w3c standard box model, setting the height/width attributes of the element refers to the height and width of the content part

  • border-box: IE traditional box model , setting the height/width attribute of the element refers to the height and width of the border padding content part

Special Recommendation:2020 CSS Interview Questions Summary (latest)

2. Use CSS3 attributes to write a triangle

<style>
p{
width: 0;
height: 0;
border-top: 40px solid transparent;
border-right: 40px solid transparent;
border-bottom: 40px solid red;
border-left: 40px solid transparent;
}
</style>
</head>
<body>
<!-- 想要改变三角形的方向只需要改变border属性值(即tblr) -->
<p></p>
</body>

3. How to understand HTML5?

(1) In the front-end field, H5 is a technology collection (technology stack), not a simple technical point, so it cannot be understood as an HTML specification.

(2), we can sort it out from three aspects: html, css, and js

                                                                                              Semantic tags, new form types, new form attributes

CSS: New selection device, transition, conversion, animation, media query

JS: Canvas drawing, ES6

## (3), from functional understanding H5 development

Mobile Web development

Responsive development

Single page application development

Hybrid APP development

WeChat applet

WeChat public account development

H5 development generally refers to the comprehensive use of the H5 technology stack (HTML improvement, CSS improvement, JavaScript improvement) to develop web applications

4. What is new in CSS3 characteristic?

(1), RGBA and transparency

(2), background-image, background-origin, background-size, background-repeat

(3) , word-wrap (wrap long indivisible words) word-wrap:break-word;

(4), text-shadow: text-shadow: 5px 5px 5px #ccc; (

Horizontal shadow, vertical shadow, blur distance, shadow color)

(5), font-face: Customize your own font

(6),

Rounded corners ( Border radius): The border-radius attribute is used to create rounded corners

(7), box-shadow box-shadow: 5px 5px 5px #ccc;

(8), Media query: Define two sets of css. When the size of the browser changes, different attributes will be used

5. Why should mobile projects use box-sizing: border-box?

box-sizing: border-box; can avoid width overflow , resulting in a horizontal scroll bar (mobile items are all non-fixed width)

6. What is the difference between display:none and visibility:hidden?

display: none does not display the corresponding element and no longer allocates space in the document layout (reflow and redraw)

visibility: hidden Hide the corresponding element and still retain the original space in the document layout (redraw)

Redraw: When some elements in the render-tree need to update attributes, these attributes only affect the appearance and style of the elements, but do not affect the layout, such as background-color, it is called redrawing.

Reflow: Reflow is required when the layout and geometric properties of the page change, such as:

##f35d6e602fd7d0f0edfa6f7d103c1b57, add or Remove visible DOM elements

2cc198a1d5eb0d3eb508d858c9f5cbdb、元素位置的改变

5bdf4c78156c7953567bb5a0aef2fc53、元素尺寸的改变(边框、尺寸、填充、宽度、高度)

23889872c2e8594e0f446a471a78ec4c、内容的改变(比如文本的改变和图片大小的改变而引起的计算值宽度和高度的改变)

43ad812d3a971134e40facaca816c822、页面渲染初始化

efbfa0de8737dc86eae413541a49df20、浏览器窗口尺寸的改变-resize事件发生时

回流必将引起重绘,重绘不一定会引起回流

7、对BFC(块级格式化上下文block formatting context)的理解?

简单的来说BFC是一种属性,这种属性会影响着元素的定位以及与其兄弟元素之间的相互作用。

8、如何居中p?如何居中一个浮动元素?如何让绝对定位的p居中?

f35d6e602fd7d0f0edfa6f7d103c1b57居中p

<style>
p{
width: 200px;
height: 200px;
margin:0 auto;
background-color: pink;
}
</style>
</head>
<body>
<p></p>
</body>

2cc198a1d5eb0d3eb508d858c9f5cbdb居中一个浮动的元素上下左右居中

<style>
p{
width: 200px;
height: 200px;
background-color: pink;
float: left;
position: absolute;
left: 50%;
top: 50%;
margin: -100px 0 0 -100px;
}
</style>
</head>
<body>
<p></p>
</body>

5bdf4c78156c7953567bb5a0aef2fc53绝对定位水平居中

<style>
p{
width: 200px;
height: 200px;
background-color: pink;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
 
}
</style>
</head>
<body>
<p></p>
</body>

9、position的值?

  • static(默认):按照正常文档流进行排列

  • relative(相对定位)不脱离文档流,参考自身的top、right、bottom、left进行定位

  • absolute(绝对定位)参考其最近的一个非static的父级元素通过top、right、bottom、left进行定位

  • fixed(固定定位)所固定的参照对象是可视窗口的位置

10、常见的兼容性问题

f35d6e602fd7d0f0edfa6f7d103c1b57不同浏览器标签默认的padding和margin不一样,*{padding:0;margin:0}

2cc198a1d5eb0d3eb508d858c9f5cbdbchorme浏览器中文界面下默认会将小于12px的文本强制按照12px显示,可通过加入css属性-webkit-text-size-adjust:none;

11、为什么会出现浮动和什么时候需要清除浮动?清除浮动的方式?

由于浮动元素不在文档流中,所以文档流的块框表现得就像浮动框不存在一样。浮动元素会漂浮在文档流的块框上。

浮动带来的问题:

f35d6e602fd7d0f0edfa6f7d103c1b57父元素的高度无法被撑开

2cc198a1d5eb0d3eb508d858c9f5cbdb与浮动元素同级的非浮动元素(内联元素)会跟随其后

5bdf4c78156c7953567bb5a0aef2fc53若非第一个元素浮动,则该元素之前的元素也需要浮动,否则会影响页面显示的结构。

清除浮动的方式:

f35d6e602fd7d0f0edfa6f7d103c1b57 父级p定义高度

2cc198a1d5eb0d3eb508d858c9f5cbdb 最后一个浮动元素后加空p标签,并添加样式clear:both

5bdf4c78156c7953567bb5a0aef2fc53 包含浮动元素的父标签添加样式overflow为hidden和auto

23889872c2e8594e0f446a471a78ec4c 父级定义zoom

相关教程推荐:CSS视频教程

The above is the detailed content of Classic CSS interview questions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete