CSS选择符有哪些? 哪些属性可以继承? 优先级算法如何计算? CSS3新增伪类有哪些?
id选择器( # myid)
2.类选择器(.myclassname)
3.标签选择器(div, h1, p)
4.相邻选择器(h1 + p)
5.子选择器(ul > li)
6.后代选择器(li a)
7.通配符选择器( * )
8.属性选择器(a[rel = "external"])
9.伪类选择器(a: hover, li:nth-child)
* 可继承的样式: font-size font-family color, text-indent;
* 不可继承的样式:border padding margin width height ;
* 优先级就近原则,同权重情况下样式定义最近者为准;
* 载入样式以最后载入的定位为准;
优先级为:
!important > id > class > tag
important 比 内联优先级高,但内联比 id 要高
CSS3新增伪类举例:
p:first-of-type 选择属于其父元素的首个 <p> 元素的每个 <p> 元素。
p:last-of-type 选择属于其父元素的最后 <p> 元素的每个 <p> 元素。
p:only-of-type 选择属于其父元素唯一的 <p> 元素的每个 <p> 元素。
p:only-child 选择属于其父元素的唯一子元素的每个 <p> 元素。
p:nth-child(2) 选择属于其父元素的第二个子元素的每个 <p> 元素。
清除浮动的几种方式
::after clear: both
clear: both
创建父级 BFC(overflow:hidden)
父级设置高度
如何做再父子盒子都不知道宽高的情况下如何盒子上下左右居中
水平居中
行内元素: text-align: center
块级元素: margin: 0 auto
position:absolute +left:50%+ transform:translateX(-50%)
display:flex + justify-content: center
垂直居中
设置line-height 等于height
position:absolute +top:50%+ transform:translateY(-50%)
display:flex + align-items: center
闭包是什么,有什么特性,对页面有什么影响
闭包就是能够读取其他函数内部变量的函数。
使得函数不被系统(GC)回收,如果过多使用闭包,容易导致内存泄露
说出两种方案在字符串和数组中转换
字符串变成数组: 字符串.split("-");
数组变成字符串: 数组名.join("-");
数组方法pop() push() unshift() shift()区别
push()尾部添加 pop()尾部删除
unshift()头部添加 shift()头部删除