search
HomeWeb Front-endCSS TutorialClassic 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>

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:

##, add or Remove visible DOM elements

、元素位置的改变

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

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

、页面渲染初始化

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

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

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

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

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

居中p

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

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

<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>

绝对定位水平居中

<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、常见的兼容性问题

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

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

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

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

浮动带来的问题:

父元素的高度无法被撑开

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

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

清除浮动的方式:

父级p定义高度

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

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

父级定义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. If there is any infringement, please contact admin@php.cn delete
How much specificity do @rules have, like @keyframes and @media?How much specificity do @rules have, like @keyframes and @media?Apr 18, 2025 am 11:34 AM

I got this question the other day. My first thought is: weird question! Specificity is about selectors, and at-rules are not selectors, so... irrelevant?

Can you nest @media and @support queries?Can you nest @media and @support queries?Apr 18, 2025 am 11:32 AM

Yes, you can, and it doesn't really matter in what order. A CSS preprocessor is not required. It works in regular CSS.

Quick Gulp Cache BustingQuick Gulp Cache BustingApr 18, 2025 am 11:23 AM

You should for sure be setting far-out cache headers on your assets like CSS and JavaScript (and images and fonts and whatever else). That tells the browser

In Search of a Stack That Monitors the Quality and Complexity of CSSIn Search of a Stack That Monitors the Quality and Complexity of CSSApr 18, 2025 am 11:22 AM

Many developers write about how to maintain a CSS codebase, yet not a lot of them write about how they measure the quality of that codebase. Sure, we have

Datalist is for suggesting values without enforcing valuesDatalist is for suggesting values without enforcing valuesApr 18, 2025 am 11:08 AM

Have you ever had a form that needed to accept a short, arbitrary bit of text? Like a name or whatever. That's exactly what is for. There are lots of

Front Conference in ZürichFront Conference in ZürichApr 18, 2025 am 11:03 AM

I'm so excited to be heading to Zürich, Switzerland for Front Conference (Love that name and URL!). I've never been to Switzerland before, so I'm excited

Building a Full-Stack Serverless Application with Cloudflare WorkersBuilding a Full-Stack Serverless Application with Cloudflare WorkersApr 18, 2025 am 10:58 AM

One of my favorite developments in software development has been the advent of serverless. As a developer who has a tendency to get bogged down in the details

Creating Dynamic Routes in a Nuxt ApplicationCreating Dynamic Routes in a Nuxt ApplicationApr 18, 2025 am 10:53 AM

In this post, we’ll be using an ecommerce store demo I built and deployed to Netlify to show how we can make dynamic routes for incoming data. It’s a fairly

See all articles

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 Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool