Home Web Front-end CSS Tutorial Classic CSS interview questions

Classic CSS interview questions

Aug 03, 2020 pm 03:18 PM
css interview questions

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!

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Let's use (X, X, X, X) for talking about specificity Let's use (X, X, X, X) for talking about specificity Mar 24, 2025 am 10:37 AM

I was just chatting with Eric Meyer the other day and I remembered an Eric Meyer story from my formative years. I wrote a blog post about CSS specificity, and

See all articles