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

Classic CSS interview questions

coldplay.xixi
Release: 2020-08-03 16:51:24
forward
4144 people have browsed it

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>
Copy after login

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:

##<1>, add or Remove visible DOM elements

<2>、元素位置的改变

<3>、元素尺寸的改变(边框、尺寸、填充、宽度、高度)

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

<5>、页面渲染初始化

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

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

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

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

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

<1>居中p

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

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

<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>
Copy after login

<3>绝对定位水平居中

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

9、position的值?

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

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

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

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

10、常见的兼容性问题

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

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

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

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

浮动带来的问题:

<1>父元素的高度无法被撑开

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

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

清除浮动的方式:

<1> 父级p定义高度

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

<3> 包含浮动元素的父标签添加样式overflow为hidden和auto

<4> 父级定义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!

Related labels:
source:csdn.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template