Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
文資料來源于
https://github.com/qiu-deqing/FE-interview
目前已在github獲得4700個star,在前端知識項目中名列第一。
上一篇主要分享了該項目中的HTML, HTTP,web綜合問題部分。
本文主要分享該項目中的CSS部分的知識點及面試題部分,后續分享剩余5個章節。
歡迎關注筆者,優質文章都在這里等你。
概念:將多個小圖片拼接到一個圖片中。通過background-position和元素尺寸調節需要顯示的背景圖案。
優點:
缺點:
聯系:它們都能讓元素不可見
區別:
原理:利用不同瀏覽器對CSS的支持和解析結果不一樣編寫針對特定瀏覽器樣式。常見的hack有1)屬性hack。2)選擇器hack。3)IE條件注釋
<!--[if IE 6]> Special instructions for IE 6 here <![endif]-->
/***** Selector Hacks ******/ /* IE6 and below */ * html #uno { color: red } /* IE7 */ *:first-child+html #dos { color: red } /* IE7, FF, Saf, Opera */ html>body #tres { color: red } /* IE8, FF, Saf, Opera (Everything but IE 6,7) */ html>/**/body #cuatro { color: red } /* Opera 9.27 and below, safari 2 */ html:first-child #cinco { color: red } /* Safari 2-3 */ html[xmlns*=""] body:last-child #seis { color: red } /* safari 3+, chrome 1+, opera9+, ff 3.5+ */ body:nth-of-type(1) #siete { color: red } /* safari 3+, chrome 1+, opera9+, ff 3.5+ */ body:first-of-type #ocho { color: red } /* saf3+, chrome1+ */ @media screen and (-webkit-min-device-pixel-ratio:0) { #diez { color: red } } /* iPhone / mobile webkit */ @media screen and (max-device-width: 480px) { #veintiseis { color: red } } /* Safari 2 - 3.1 */ html[xmlns*=""]:root #trece { color: red } /* Safari 2 - 3.1, Opera 9.25 */ *|html[xmlns*=""] #catorce { color: red } /* Everything but IE6-8 */ :root *> #quince { color: red } /* IE7 */ *+html #dieciocho { color: red } /* Firefox only. 1+ */ #veinticuatro, x:-moz-any-link { color: red } /* Firefox 3.0+ */ #veinticinco, x:-moz-any-link, x:default { color: red }
/* IE6 */ #once { _color: blue } /* IE6, IE7 */ #doce { *color: blue; /* or #color: blue */ } /* Everything but IE6 */ #diecisiete { color/**/: blue } /* IE6, IE7, IE8 */ #diecinueve { color: blue\9; } /* IE7, IE8 */ #veinte { color/*\**/: blue\9; } /* IE6, IE7 -- acts as an !important */ #veintesiete { color: blue !ie; } /* string after ! can be anything */
specified value,computed value,used value計算方法
link與@import的區別
參考資料: 選擇正確的圖片格式 GIF:
JPEG:
PNG:
CSS有哪些繼承屬性
.target { min-height: 100px; height: auto !important; height: 100px; // IE6下內容高度超過會自動擴展高度 }
<style type="text/css"> .outer { width: 215px; height: 100px; border: 1px solid red; overflow: auto; position: relative; /* 修復bug */ } .inner { width: 100px; height: 200px; background-color: purple; position: relative; } </style> <div class="outer"> <div class="inner"></div> </div>
<style type="text/css"> .p:hover, .hover { background: purple; } </style> <p class="p" id="target">aaaa bbbbb<span>DDDDDDDDDDDd</span> aaaa lkjlkjdf j</p> <script type="text/javascript"> function addClass(elem, cls) { if (elem.className) { elem.className += ' ' + cls; } else { elem.className = cls; } } function removeClass(elem, cls) { var className = ' ' + elem.className + ' '; var reg = new RegExp(' +' + cls + ' +', 'g'); elem.className = className.replace(reg, ' ').replace(/^ +| +$/, ''); } var target = document.getElementById('target'); if (target.attachEvent) { target.attachEvent('onmouseenter', function () { addClass(target, 'hover'); }); target.attachEvent('onmouseleave', function () { removeClass(target, 'hover'); }) } </script>
.opacity { opacity: 0.4 filter: alpha(opacity=60); /* for IE5-7 */ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=60)"; /* for IE 8*/ }
display: inline-block; *display: inline; *zoom: 1;
容器包含若干浮動元素時如何清理(包含)浮動
/** * 在標準瀏覽器下使用 * 1 content內容為空格用于修復opera下文檔中出現 * contenteditable屬性時在清理浮動元素上下的空白 * 2 使用display使用table而不是block:可以防止容器和 * 子元素top-margin折疊,這樣能使清理效果與BFC,IE6/7 * zoom: 1;一致 **/ .clearfix:before, .clearfix:after { content: " "; /* 1 */ display: table; /* 2 */ } .clearfix:after { clear: both; } /** * IE 6/7下使用 * 通過觸發hasLayout實現包含浮動 **/ .clearfix { *zoom: 1; }
Flash Of Unstyled Content:用戶定義樣式表加載之前瀏覽器使用默認樣式顯示文檔,用戶樣式加載渲染之后再從新顯示文檔,造成頁面閃爍。解決方法:把樣式表放到文檔的head
如何創建塊級格式化上下文(block formatting context),BFC有什么用
創建規則:
作用:
外邊距折疊(collapsing margins)
毗鄰的兩個或多個margin會合并成一個margin,叫做外邊距折疊。規則如下:
如何確定一個元素的包含塊(containing block)
z軸上的默認層疊順序如下(從下到上):
如何創建stacking context:
<body> <div class="content"> aaaaaa aaaaaa a a a a a a a a </div> </body> <style> body { background: #DDD; text-align: center; /* 3 */ } .content { width: 500px; /* 1 */ text-align: left; /* 3 */ margin: 0 auto; /* 2 */ background: purple; } </style>
<body> <div class="content"> aaaaaa aaaaaa a a a a a a a a </div> </body> <style> body { background: #DDD; } .content { width: 500px; /* 1 */ float: left; position: relative; /* 2 */ left: 50%; /* 3 */ margin-left: -250px; /* 4 */ background-color: purple; } </style>
<body> <div class="content"> aaaaaa aaaaaa a a a a a a a a </div> </body> <style> body { background: #DDD; position: relative; } .content { width: 800px; position: absolute; left: 50%; margin-left: -400px; background-color: purple; } </style>
<body> <div class="content"> aaaaaa aaaaaa a a a a a a a a </div> </body> <style> body { background: #DDD; position: relative; } .content { width: 800px; position: absolute; margin: 0 auto; left: 0; right: 0; background-color: purple; } </style>
如何豎直居中一個元素
參考資料:6 Methods For Vertical Centering With CSS。 盤點8種CSS實現垂直居中
<p class="text">center text</p> <style> .text { line-height: 200px; } </style>
對大廠架構設計,BAT等廠家面試題解讀,編程語言理論或者互聯網圈逸聞趣事這些感興趣,歡迎關注筆者,沒有錯,干貨文章都在這里。
function fn1() {
setTimeout(() => {
console.log('fn1執行')
fn2('fn1傳遞過去的參數')
}, 1000)
}
function fn2(data) {
setTimeout(() => {
console.log('fn2執行', data)
fn3('fn2傳遞過去的參數')
}, 1000)
}
function fn3(data) {
setTimeout(() => {
console.log('fn3執行', data)
}, 1000)
}
fn1()
執行結果如下:
我們發現這種方式雖然能實現,但是代碼量一旦變多,可讀性就降低了。
function fn1() {
return new Promise((resolve, reject) => {
console.log('fn1執行')
setTimeout(() => {
console.log('fn1結束')
resolve('fn1傳遞過去的參數')
}, 1000)
})
}
function fn2(data) {
return new Promise((resolve, reject) => {
console.log('fn2執行,接收的參數', data)
setTimeout(() => {
resolve('fn2傳遞過去的參數')
}, 1000)
})
}
function fn3(data) {
return new Promise((resolve, reject) => {
console.log('fn3執行,接收的參數', data)
setTimeout(() => {
resolve('fn3傳遞過去的參數')
}, 1000)
})
}
fn1().then(fn2).then(fn3).then(res => {
console.log('最后一個', res)
})
生成器就是能返回一個迭代器的函數,它也是一個函數,對比普通的函數,多了一個*,在它的函數體內可以使用yield關鍵字,函數會在每個yield后暫停,等待,直到這個生成的對象,調用下一個next(),每調用一次next會往下執行一次yieId,然后暫停。
、下面關于WEB開發中,常見的技術和問題描述正確的是:(多選)
A、CSS selector中,支持按照元素的id選擇,元素的名稱進行選擇,元素的class屬性進行選擇,比如 “#div .red”就是選擇CSS class屬性中包括red的所有的div元素
B、JSON是一種以JavaScript語法表示的數據對象格式,比如描述一個學生,包括,其中,姓名,年齡就可以這樣表達 {name: "John", age: 18}
C、HTML頁面中的第一個指令: 表明這是一個符合HTML5標準的頁面
D、不同的瀏覽器對HTML渲染的方式稍有差異,但是所有的主流瀏覽器都支持JavaScript語言,而且提供的JavaScript的編程環境都是一致的
E、HTML頁面裝載時,首先把整個HTML頁面下載下來,再根據HTML中出現的順序依次下載它引用的外部的JavaScript代碼和圖片資源,最后才執行頁面中的JavaScript代碼
F、JavaScript中的函數就是一個對象,每個函數對象都繼承了JavaScript的Function類
正確答案: C
解析:
A.“#div .red”就是選擇CSS class屬性中包括red的所有Id為div元素
B.{"name": "John", "age": 18},json數據中的鍵都需要添加""(雙引號)
D.不同瀏覽器提供的編程環境不一致(包括html、css、js編程的不一致),所以在編程時才要使用 -ms、-webkit、-moz來實現不同瀏覽器的兼容性(解決css編程不一致)
E.JS文件按在HTML中引入的順序依次載入(不是最后載入),在載入后馬上執行,執行時會阻塞頁面后續的內容(包括頁面的渲染、其它資源的下載)
F.箭頭函數沒有super關鍵字,所以箭頭函數沒有繼承任何對象,也就不可能繼承Function類。
2、以下描述正確的是:(多選)
A、`inline-block` 可以設置高度,`inline` 不可以設置高度
B、`inline-block` 和 `inline` 都可以設置 `padding-left`
C、`inline-block` 可以設置 `margin-left`,inline 不可以
D、`block` 會獨占一行,`inline-block` 不會
正確答案: A、B、D
解析:
行內元素不可以設置元素寬高,但是可以設置 左右padding、左右margin
img、input屬于行內替換元素。height/width/padding/margin均可用。效果等于塊元素
3、對于以下 HTML,下列選項中哪一個 CSS 選擇器效果與其他的不同:
```html
<p><span>A</span><span>B</span><span>C</span></p>
```
A、`span:first-child`
B、`span:nth-child(0)`
C、`span:nth-child(-n+1)`
D、`span:nth-last-child(3)`
正確答案: B
解析:
:nth-child(-n+4)選取小于等于4標簽, nth-child最小從1開始
4、input 元素中,下列哪個類型屬性定義了輸入電話號碼的控件?
A、mob
B、tel
C、mobile
D、telephone
正確答案: B
5、以下選項中,哪些是html5 input的新屬性(多選)
A、file
B、search
C、number
D、reset
E、tel
正確答案: B、C、E
解析:
在HTML5中,為input元素新增了以下一些type屬性值:
*請認真填寫需求信息,我們會在24小時內與您取得聯系。