本次文件是根据简书一个面试文集而来。用面试题来驱动学习原始文集面试题
html 页面导入样式时,使用link和@import有什么区别?
- 区别一 link是xml标签,除了加载css外,还可以定义RSS等其他的业务,@import 属于css范畴,只能加载css。
- 区别二:link加载css的时候,在页面加载时同时完成,@import需要页面完全加载以后加载
- 区别三: link属于XHTML标签,无兼容性,@important是在css2.1提出来,低版本不支持
区别四:link支持使用JavaScript控制DOM去改变样式,二@import不支持
圣杯布局和双飞翼布局的理解和区别,并用代码实现
圣杯布局为了中间div不被遮挡,讲中间div设置为左右padding-left 和padding-right,讲左边两个div用相对布局position:relative并分别配合right和left属性,已方便左右两div移动后不遮挡中间div。双飞燕布局,为看中间div内容不被遮挡,直接在中间div创建子div放内容,在该子div中用margin-left margin-right为两个div流出位置
圣杯布局
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="hd">header</div>
<div id="bd">
<div id="middle">middle</div>
<div id="left">left</div>
<div id="right">right</div>
</div>
<div id="footer">footer</div>
</body>
<style>
#hd{
height:50px;
background: #666;
text-align: center;
}
#bd{
/*左右栏通过添加负的margin放到正确的位置了,此段代码是为了摆正中间栏的位置*/
padding:0 200px 0 180px;
height:100px;
}
#middle{
float:left;
width:100%;/*左栏上去到第一行*/
height:100px;
background:blue;
}
#left{
float:left;
width:180px;
height:100px;
margin-left:-100%;
background:#0c9;
/*中间栏的位置摆正之后,左栏的位置也相应右移,通过相对定位的left恢复到正确位置*/
position:relative;
left:-180px;
}
#right{
float:left;
width:200px;
height:100px;
margin-left:-200px;
background:#0c9;
/*中间栏的位置摆正之后,右栏的位置也相应左移,通过相对定位的right恢复到正确位置*/
position:relative;
right:-200px;
}
#footer{
height:50px;
background: #666;
text-align: center;
}
</style>
</html>
双飞布局
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="hd">header</div>
<div id="middle">
<div id="inside">middle</div>
</div>
<div id="left">left</div>
<div id="right">right</div>
<div id="footer">footer</div>
</body>
<style>
#hd{
height:50px;
background: #666;
text-align: center;
}
#middle{
float:left;
width:100%;/*左栏上去到第一行*/
height:100px;
background:blue;
}
#left{
float:left;
width:180px;
height:100px;
margin-left:-100%;
background:#0c9;
}
#right{
float:left;
width:200px;
height:100px;
margin-left:-200px;
background:#0c9;
}
/*给内部div添加margin,把内容放到中间栏,其实整个背景还是100%*/
#inside{
margin:0 200px 0 180px;
height:100px;
}
#footer{
clear:both; /*记得清楚浮动*/
height:50px;
background: #666;
text-align: center;
}
</style>
</html>
用递归算法实现,数组长度为5且元素的随机数在2-32间不重复的值
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script>
function randoms(index, results = [],close =5) {
if (index == close){
return
}
let rand =2+Math.floor(Math.random()*30);
console.log(rand)
let value = rand
console.log("value",value)
// value=Math.floor(value)
if (!results.includes(value)) {
results.push(parseInt(value) )
index++
}
randoms(index,results,close)
}
let a = []
randoms(0,a,5)
console.log(a)
</script>
</html>
网友评论