小米-前端工程师-面试-凉经
一、css 层级问题
两个元素,现在B叠在A上,你想让A叠在B上,就设置了A的z-index大于B的。但你发现设置后B还是叠在A上,你觉得可能是哪些原因导致没有生效呢?
z-index的元素position,没有设置为relative;
二、布局题 3个子元素
用 html+css 实现如下布局:父元素宽度未知,三个子元素默认间距30px, 但当父元素不够宽时,三个子元素的间距会自动缩小。
<!DOCTYPE html> <html> <body> <div class="parent"> <div class="child a">A</div> <div class="item"></div> <div class="child b">B</div> <div class="item"></div> <div class="child c">C</div> </div> </body> <style> .parent{ background: grey; width: 100%; height: 200px; display:flex; justify-content:center; align-items:center; } .child{ background: red; width: 50px; height: 50px; justify-self:center; flex-shrink:0 } .item{ width:30px } </style> </html>
三、算法 大数组中移除小数组
有两个数组,想要从大数组中移除最少数量的元素,使得两个数组不再有交集。返回改变后的大数组。
例:
大:[1, 3, 4, 2, 5, 6, 7, 8, 9]
小:[13, 2, 3, 5, 7]
结果: [1, 4, 6, 8, 9]
时间复杂度尽量低
let arr = [1, 3, 4, 2, 5, 6, 7, 8, 9]; let to_remove=[13, 2, 3, 5, 7]; let res = []; arr.filter(item =>{ if(!to_remove.includes(item)){ res.push(item) } })