-
Notifications
You must be signed in to change notification settings - Fork 0
/
fe-css.html
308 lines (290 loc) · 40.4 KB
/
fe-css.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>前端面试题--css篇 | 小李の博客</title><meta name="keywords" content="前端面试题"><meta name="author" content="Pride_Lee"><meta name="copyright" content="Pride_Lee"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="一些css的前端面试题总结">
<meta property="og:type" content="article">
<meta property="og:title" content="前端面试题--css篇">
<meta property="og:url" content="https://lhx.zzux.com/fe-css.html">
<meta property="og:site_name" content="小李の博客">
<meta property="og:description" content="一些css的前端面试题总结">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s1.ax1x.com/2022/07/22/jLbI8P.png">
<meta property="article:published_time" content="2021-07-21T10:06:04.000Z">
<meta property="article:modified_time" content="2022-08-05T10:57:25.848Z">
<meta property="article:author" content="Pride_Lee">
<meta property="article:tag" content="面试题">
<meta property="article:tag" content="css">
<meta property="article:tag" content="前端">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s1.ax1x.com/2022/07/22/jLbI8P.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://lhx.zzux.com/fe-css"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="google-site-verification" content="gHN_afDedvo00U6YhKTblmdcWb6sw0-3uRkGD1xwr28"/><meta name="baidu-site-verification" content="code-kFbZe5nv4p"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
root: '/',
algolia: undefined,
localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容:${query}"}},
translate: undefined,
noticeOutdate: undefined,
highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
copy: {
success: '复制成功',
error: '复制错误',
noSupport: '浏览器不支持'
},
relativeDate: {
homepage: false,
post: false
},
runtime: '',
date_suffix: {
just: '刚刚',
min: '分钟前',
hour: '小时前',
day: '天前',
month: '个月前'
},
copyright: {"limitCount":50,"languages":{"author":"作者: Pride_Lee","link":"链接: ","source":"来源: 小李の博客","info":"著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。"}},
lightbox: 'fancybox',
Snackbar: undefined,
source: {
justifiedGallery: {
js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
}
},
isPhotoFigcaption: false,
islazyload: false,
isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
title: '前端面试题--css篇',
isPost: true,
isHome: false,
isHighlightShrink: false,
isToc: true,
postUpdate: '2022-08-05 18:57:25'
}</script><noscript><style type="text/css">
#nav {
opacity: 1
}
.justified-gallery img {
opacity: 1
}
#recent-posts time,
#post-meta time {
display: inline !important
}
</style></noscript><script>(win=>{
win.saveToLocal = {
set: function setWithExpiry(key, value, ttl) {
if (ttl === 0) return
const now = new Date()
const expiryDay = ttl * 86400000
const item = {
value: value,
expiry: now.getTime() + expiryDay,
}
localStorage.setItem(key, JSON.stringify(item))
},
get: function getWithExpiry(key) {
const itemStr = localStorage.getItem(key)
if (!itemStr) {
return undefined
}
const item = JSON.parse(itemStr)
const now = new Date()
if (now.getTime() > item.expiry) {
localStorage.removeItem(key)
return undefined
}
return item.value
}
}
win.getScript = url => new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = url
script.async = true
script.onerror = reject
script.onload = script.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
script.onload = script.onreadystatechange = null
resolve()
}
document.head.appendChild(script)
})
win.activateDarkMode = function () {
document.documentElement.setAttribute('data-theme', 'dark')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
}
}
win.activateLightMode = function () {
document.documentElement.setAttribute('data-theme', 'light')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
}
}
const t = saveToLocal.get('theme')
if (t === 'dark') activateDarkMode()
else if (t === 'light') activateLightMode()
const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
if (asideStatus === 'hide') {
document.documentElement.classList.add('hide-aside')
} else {
document.documentElement.classList.remove('hide-aside')
}
}
const detectApple = () => {
if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
document.documentElement.classList.add('apple')
}
}
detectApple()
})(window)</script><meta name="generator" content="Hexo 6.2.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://s1.ax1x.com/2022/07/05/jNgtYj.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">19</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">13</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">14</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间线</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s1.ax1x.com/2022/07/22/jLbI8P.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小李の博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间线</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">前端面试题--css篇</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-07-21T10:06:04.000Z" title="发表于 2021-07-21 18:06:04">2021-07-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-08-05T10:57:25.848Z" title="更新于 2022-08-05 18:57:25">2022-08-05</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%89%8D%E7%AB%AF/">前端</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%89%8D%E7%AB%AF/css/">css</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%89%8D%E7%AB%AF/css/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.3k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>4分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="前端面试题--css篇"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="css权重优先级"><a href="#css权重优先级" class="headerlink" title="css权重优先级"></a>css权重优先级</h2><p>权重优先级从高到低:</p>
<ul>
<li><p>!important</p>
</li>
<li><p>id选择器</p>
</li>
<li><p>类选择器、属性选择器、伪类选择器</p>
</li>
<li><p>标签选择器、伪元素选择器</p>
</li>
<li><p>通配符选择器</p>
</li>
<li><p>继承</p>
</li>
</ul>
<h2 id="css3有哪些新特性"><a href="#css3有哪些新特性" class="headerlink" title="css3有哪些新特性"></a>css3有哪些新特性</h2><p>0.<code>flex布局</code></p>
<p>1.颜色:新增RGBA,HSLA模式</p>
<p>2.文字阴影(text-shadow)</p>
<p>3.<code>边框:圆角(border-radius)</code>、 边框阴影(box-shadow)</p>
<p>4.<code>盒子模型</code>:box-sizing</p>
<p>5.背景:background-size设置背景图片的尺寸、background-origin设置背景图片的原点、background-clip设置背景图片的裁切区域,以“,”分割可以设置多背景,用于自适应布局。</p>
<p>6.渐变:linear-gradient、radial-gradient</p>
<p>7.<code>过渡:transition</code>可实现动画</p>
<p>8.自定义动画</p>
<p>9.在css3中唯一引入的伪元素:selection</p>
<p>10.媒体查询、多栏布局</p>
<p>11.border-image</p>
<p>12.2D转换:transform</p>
<p>13.3D转换</p>
<h2 id="两栏布局右边固定左边自适应"><a href="#两栏布局右边固定左边自适应" class="headerlink" title="两栏布局右边固定左边自适应"></a>两栏布局右边固定左边自适应</h2><p>两个div盒子</p>
<p>第一种方式:flex布局</p>
<p>先给父盒子设置display:flex让两个子盒子一行显示,给右边盒子固定宽度,左边盒子flex:1</p>
<p>第二种方式:定位+overflow</p>
<h2 id="重绘与回流"><a href="#重绘与回流" class="headerlink" title="重绘与回流"></a>重绘与回流</h2><p>回流必定会引起重绘,重绘不一定会引起回流。</p>
<blockquote>
<p>回流(reflow):当页面中的元素宽高、布局、显示、隐藏或元素内部文字结结构发生改变时,会影响自身及其父元素、甚至追溯到更多的祖先元素发生改变,则会导致元素内部、周围甚至整个页面的重新渲染,页面发生重构,回流就产生了。</p>
</blockquote>
<blockquote>
<p> 重绘(repaint):元素的结构(宽高、布局、显示隐藏、内部文字大小)未发生改变,只是元素的外观样式发生改变,比如背景颜色、内部文字颜色、边框颜色等。此时会引起浏览器重绘,重绘的速度快于回流。</p>
</blockquote>
<h2 id="css实现三角形"><a href="#css实现三角形" class="headerlink" title="css实现三角形"></a>css实现三角形</h2><p><strong>使用boder属性</strong></p>
<p>给定一个宽度和高度都为 0 的元素,其 border 的任何值都会直接相交,我们可以利用这个交点来创建三角形。也就是说,border属性是三角形组成的,下面给每一边都提供不同的边框颜色:</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.triangle</span> {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">100px</span> solid;</span><br><span class="line"> <span class="attribute">border-color</span>: orangered skyblue gold yellowgreen;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>将元素的长宽都设置为0,效果就是四个三角形组成的正方形,如果想要一个指向下面的三角形,可以让 border 的上边可见,其他边都设置为透明,其他方向同理。</p>
<h2 id="如何实现0-5像素"><a href="#如何实现0-5像素" class="headerlink" title="如何实现0.5像素"></a>如何实现0.5像素</h2><p>1.伪元素+scale</p>
<p>给容器设置伪元素,设置绝对定位,宽高200%,边框1px,然后使用transform:scale(0.5) 让伪元素缩小原来的一半,此时伪元素的边框和容器的边缘重合</p>
<p>2: 伪元素+背景 (适合设置一条边框,没办法展示圆角)<br>实现方式:给容器设置伪元素,设置绝对定位,高度1px,背景图设置线性渐变,一半有颜色一半透明,视觉上只有0.5px。</p>
<p>3: 利用阴影代替边框<br>特点:方便,能正常展示圆角,而且能实现0.1px等更细的边框,兼容性还行。</p>
<h2 id="盒子水平垂直居中"><a href="#盒子水平垂直居中" class="headerlink" title="盒子水平垂直居中"></a>盒子水平垂直居中</h2><p>1.纯flex</p>
<p>父盒子开启flex,主轴居中、侧轴居中即可</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">display: flex;</span><br><span class="line"></span><br><span class="line">justify-content: center;</span><br><span class="line"></span><br><span class="line">align-items: center;</span><br></pre></td></tr></table></figure>
<p>2.flex + margin</p>
<blockquote>
<p>父盒子 display: flex;</p>
<p>子盒子 margin: auto;</p>
</blockquote>
<blockquote>
<mark class="hl-label red">注意:</mark> 纯margin虽然也能实现,但是如果大小发生改变则会出问题
</blockquote>
<p>3.定位 + transform</p>
<blockquote>
<p>子绝父相</p>
<p>给父盒子相对定位:</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">position: relative;</span><br></pre></td></tr></table></figure>
<p>给子盒子绝对定位:</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">position: absolute;</span><br><span class="line">top: 50%;</span><br><span class="line">left: 50%;</span><br><span class="line">transform: translate(-50%,-50%); //减去自身的50%</span><br></pre></td></tr></table></figure>
</blockquote>
<p>4.定位 + margin</p>
<blockquote>
<p>子绝父相</p>
<p>给父盒子相对定位:</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">position: relative;</span><br></pre></td></tr></table></figure>
<p>给子盒子绝对定位:</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">position: absolute;</span><br><span class="line">top: 0;</span><br><span class="line">bottom: 0;</span><br><span class="line">left: 0;</span><br><span class="line">right: 0;</span><br><span class="line">margin: auto;</span><br></pre></td></tr></table></figure>
</blockquote>
<h2 id="盒模型"><a href="#盒模型" class="headerlink" title="盒模型"></a>盒模型</h2><blockquote>
<p>盒模型由内往外主要分为四个部分:内容、内边距、边框、外边距</p>
</blockquote>
<p><img src="https://s1.ax1x.com/2022/08/01/vAF4Fx.png" alt="盒模型"></p>
<h3 id="标准盒模型"><a href="#标准盒模型" class="headerlink" title="标准盒模型"></a>标准盒模型</h3><blockquote>
<p>默认是标准盒模型,width和height只是内容的宽高,所以盒子的实际大小应加上:内边距、边框</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">style</span>></span><span class="language-css"></span></span><br><span class="line"><span class="language-css"> * {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">padding</span>: <span class="number">0</span>;</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"> <span class="selector-class">.father</span> {</span></span><br><span class="line"><span class="language-css"> <span class="attribute">width</span>: <span class="number">200px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">height</span>: <span class="number">200px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">background-color</span>: skyblue;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">padding</span>: <span class="number">10px</span>;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">border</span>: <span class="number">10px</span> solid pink;</span></span><br><span class="line"><span class="language-css"> <span class="attribute">margin</span>: <span class="number">10px</span>;</span></span><br><span class="line"><span class="language-css"> }</span></span><br><span class="line"><span class="language-css"></span><span class="tag"></<span class="name">style</span>></span></span><br><span class="line"> //其他代码省略</span><br><span class="line"> </span><br><span class="line"> <span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"father"</span>></span><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure>
<p><img src="https://s1.ax1x.com/2022/08/01/vAEnL4.png" alt="盒模型面积"></p>
<p>所以盒子最终的宽高是240*240</p>
<h3 id="怪异盒模型-x2F-c3盒模型-x2F-ie盒模型"><a href="#怪异盒模型-x2F-c3盒模型-x2F-ie盒模型" class="headerlink" title="怪异盒模型/c3盒模型/ie盒模型"></a>怪异盒模型/c3盒模型/ie盒模型</h3><p>通过设置box-sizing: border-box;可以设置为怪异盒模型,实际盒子大小就是设置的宽高,包含内容+padding+border。</p>
<p><img src="https://s1.ax1x.com/2022/08/01/vAVeht.png" alt="怪异盒模型"></p>
<h2 id="flex"><a href="#flex" class="headerlink" title="flex"></a>flex</h2><h3 id="flex1"><a href="#flex1" class="headerlink" title="flex1"></a>flex1</h3><blockquote>
<p>flex1展开为:</p>
<p>flex-grow:1</p>
<p>flex-shink:1</p>
<p>flex-basis:0%</p>
</blockquote>
<p>1.<code>flex-grow</code> 是用来增大盒子的,比如,当父盒子的宽度大于子盒子的宽度,父盒子的剩余空间可以利用flex-grow来设置子盒子增大的占比。 </p>
<p>2.<code>flex-shink</code> 是用来设置子盒子超过父盒子的宽度后,进行缩小的比例值。</p>
<p>3.<code>flex-basis </code> 设置盒子的基准宽度,并且basis存在时会使width失效。(可以理解为basis比width优先级高)</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://lhx.zzux.com">Pride_Lee</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://lhx.zzux.com/fe-css.html">https://lhx.zzux.com/fe-css.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外,均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://lhx.zzux.com" target="_blank">小李の博客</a>!</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a><a class="post-meta__tags" href="/tags/css/">css</a><a class="post-meta__tags" href="/tags/%E5%89%8D%E7%AB%AF/">前端</a></div><div class="post_share"><div class="social-share" data-image="https://s1.ax1x.com/2022/07/22/jLbI8P.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src="/img/wechat.jpg" alt="wechat"/></a><div class="post-qr-code-desc">wechat</div></li><li class="reward-item"><a href="/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="/img/alipay.jpg" alt="alipay"/></a><div class="post-qr-code-desc">alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/data-type.html"><img class="prev-cover" src="https://s1.ax1x.com/2022/07/05/jNqUyD.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">js数据类型和数据类型检测</div></div></a></div><div class="next-post pull-right"><a href="/FE-html.html"><img class="next-cover" src="https://s1.ax1x.com/2022/07/21/jqyBjK.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">前端面试题--html篇</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/fe-bfc.html" title="什么是BFC?它的作用是什么以及怎么创建BFC区域"><img class="cover" src="https://s1.ax1x.com/2022/07/22/jOrC59.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-22</div><div class="title">什么是BFC?它的作用是什么以及怎么创建BFC区域</div></div></a></div><div><a href="/FE-html.html" title="前端面试题--html篇"><img class="cover" src="https://s1.ax1x.com/2022/07/21/jqyBjK.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-07-20</div><div class="title">前端面试题--html篇</div></div></a></div><div><a href="/chrome-cache.html" title="浏览器的缓存机制"><img class="cover" src="https://s1.ax1x.com/2022/07/25/jvWCsH.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-09-23</div><div class="title">浏览器的缓存机制</div></div></a></div><div><a href="/watcher-release.html" title="观察者模式与发布订阅模式"><img class="cover" src="https://s1.ax1x.com/2022/07/28/vCgOAJ.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-24</div><div class="title">观察者模式与发布订阅模式</div></div></a></div><div><a href="/fe-float.html" title="什么是浮动以及清除浮动的方法"><img class="cover" src="https://s1.ax1x.com/2022/07/05/jNqUyD.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-15</div><div class="title">什么是浮动以及清除浮动的方法</div></div></a></div><div><a href="/fe-vuex.html" title="什么是Vuex?"><img class="cover" src="https://s1.ax1x.com/2022/07/05/jNjg4s.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-07-23</div><div class="title">什么是Vuex?</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div><div id="comment-switch"><span class="first-comment">Valine</span><span class="switch-btn"></span><span class="second-comment">Livere</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div><div><div id="lv-container" data-id="city" data-uid="MTAyMC81Njc0OS8zMzIxMw=="></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://s1.ax1x.com/2022/07/05/jNgtYj.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Pride_Lee</div><div class="author-info__description">99年的Fe(前端)小菜鸡一枚~</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">19</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">13</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">14</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/Pride-lee"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/Pride-lee" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="http://wpa.qq.com/msgrd?v=3&uin=211977992&site=qq&menu=yes" target="_blank" title="qq"><i class="fa-brands fa-qq"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">99年程序猿,兴趣爱好多,代码、软件硬件、智能家居、穿越机甚至钓鱼,喜欢一切有意思的东西❤️🧡💛💚💙💜</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#css%E6%9D%83%E9%87%8D%E4%BC%98%E5%85%88%E7%BA%A7"><span class="toc-number">1.</span> <span class="toc-text">css权重优先级</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css3%E6%9C%89%E5%93%AA%E4%BA%9B%E6%96%B0%E7%89%B9%E6%80%A7"><span class="toc-number">2.</span> <span class="toc-text">css3有哪些新特性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%A4%E6%A0%8F%E5%B8%83%E5%B1%80%E5%8F%B3%E8%BE%B9%E5%9B%BA%E5%AE%9A%E5%B7%A6%E8%BE%B9%E8%87%AA%E9%80%82%E5%BA%94"><span class="toc-number">3.</span> <span class="toc-text">两栏布局右边固定左边自适应</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%87%8D%E7%BB%98%E4%B8%8E%E5%9B%9E%E6%B5%81"><span class="toc-number">4.</span> <span class="toc-text">重绘与回流</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css%E5%AE%9E%E7%8E%B0%E4%B8%89%E8%A7%92%E5%BD%A2"><span class="toc-number">5.</span> <span class="toc-text">css实现三角形</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B00-5%E5%83%8F%E7%B4%A0"><span class="toc-number">6.</span> <span class="toc-text">如何实现0.5像素</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%92%E5%AD%90%E6%B0%B4%E5%B9%B3%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD"><span class="toc-number">7.</span> <span class="toc-text">盒子水平垂直居中</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%92%E6%A8%A1%E5%9E%8B"><span class="toc-number">8.</span> <span class="toc-text">盒模型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%87%E5%87%86%E7%9B%92%E6%A8%A1%E5%9E%8B"><span class="toc-number">8.1.</span> <span class="toc-text">标准盒模型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%80%AA%E5%BC%82%E7%9B%92%E6%A8%A1%E5%9E%8B-x2F-c3%E7%9B%92%E6%A8%A1%E5%9E%8B-x2F-ie%E7%9B%92%E6%A8%A1%E5%9E%8B"><span class="toc-number">8.2.</span> <span class="toc-text">怪异盒模型/c3盒模型/ie盒模型</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#flex"><span class="toc-number">9.</span> <span class="toc-text">flex</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#flex1"><span class="toc-number">9.1.</span> <span class="toc-text">flex1</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/jd-yangmao.html" title="全自动薅JD羊毛"><img src="https://s1.ax1x.com/2022/07/05/jNqUyD.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="全自动薅JD羊毛"/></a><div class="content"><a class="title" href="/jd-yangmao.html" title="全自动薅JD羊毛">全自动薅JD羊毛</a><time datetime="2023-03-12T14:45:28.000Z" title="发表于 2023-03-12 22:45:28">2023-03-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/mini-program-2.html" title="微信小程序知识点(二)"><img src="https://s1.ax1x.com/2022/07/05/jNjg4s.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="微信小程序知识点(二)"/></a><div class="content"><a class="title" href="/mini-program-2.html" title="微信小程序知识点(二)">微信小程序知识点(二)</a><time datetime="2022-11-28T12:13:10.000Z" title="发表于 2022-11-28 20:13:10">2022-11-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/mini-program.html" title="微信小程序知识点(一)"><img src="https://s1.ax1x.com/2022/07/05/jNqUyD.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="微信小程序知识点(一)"/></a><div class="content"><a class="title" href="/mini-program.html" title="微信小程序知识点(一)">微信小程序知识点(一)</a><time datetime="2022-11-27T11:45:28.000Z" title="发表于 2022-11-27 19:45:28">2022-11-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/chrome-cache.html" title="浏览器的缓存机制"><img src="https://s1.ax1x.com/2022/07/25/jvWCsH.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="浏览器的缓存机制"/></a><div class="content"><a class="title" href="/chrome-cache.html" title="浏览器的缓存机制">浏览器的缓存机制</a><time datetime="2022-09-23T12:20:28.000Z" title="发表于 2022-09-23 20:20:28">2022-09-23</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/fe-vuex.html" title="什么是Vuex?"><img src="https://s1.ax1x.com/2022/07/05/jNjg4s.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="什么是Vuex?"/></a><div class="content"><a class="title" href="/fe-vuex.html" title="什么是Vuex?">什么是Vuex?</a><time datetime="2022-07-23T10:06:04.000Z" title="发表于 2022-07-23 18:06:04">2022-07-23</time></div></div></div></div></div></div></main><footer id="footer" style="background: rgb(252,118,153)radial-gradient(circle, rgba(252,118,153,1) 0%, rgba(139,216,238,1) 100%);"><div id="footer-wrap"><div class="copyright">©2020 - 2023 By Pride_Lee</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span> 数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
endLoading: () => {
document.body.style.overflow = 'auto';
document.getElementById('loading-box').classList.add("loaded")
},
initLoading: () => {
document.body.style.overflow = '';
document.getElementById('loading-box').classList.remove("loaded")
}
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadValine () {
function initValine () {
const valine = new Valine(Object.assign({
el: '#vcomment',
appId: 'tLdhKVV1NoSACqDtL4PqycT5-gzGzoHsz',
appKey: 'V6GdVccl5jFRALt0jxwvRWNO',
avatar: 'monsterid',
serverURLs: '',
emojiMaps: "",
path: window.location.pathname,
visitor: false
}, null))
}
if (typeof Valine === 'function') initValine()
else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}
if ('Valine' === 'Valine' || !false) {
if (false) btf.loadComment(document.getElementById('vcomment'),loadValine)
else setTimeout(loadValine, 0)
} else {
function loadOtherComment () {
loadValine()
}
}</script><script>function loadLivere () {
if (typeof LivereTower === 'object') {
window.LivereTower.init()
}
else {
(function(d, s) {
var j, e = d.getElementsByTagName(s)[0];
if (typeof LivereTower === 'function') { return; }
j = d.createElement(s);
j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
j.async = true;
e.parentNode.insertBefore(j, e);
})(document, 'script');
}
}
if ('Valine' === 'Livere' || !false) {
if (false) btf.loadComment(document.getElementById('lv-container'), loadLivere)
else loadLivere()
}
else {
function loadOtherComment () {
loadLivere()
}
}</script></div><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>