1、absolute 和 relative 分别依据什么定位?
relative依据自身定位
absolute依据最近一层的定位元素定位
定位元素:
- absolute relative fixed
- body
2、居中对齐有哪些实现方式?
水平居中
- inline元素:
text-align: center
- block元素:
margin: auto
- absolute元素:
left: 50% + margin-left 负值
垂直居中
- inline 元素:
line-height
的值等于height
的值 - absolute 元素:
top:50% + margin-top 负值
- absolute 元素:
transform:translate(-50%,-50%)
- absolute 元素:
top,left,bottom,right = 0 + margin: auto
3、line-height继承问题
<style>
body {
font-size: 20px;
line-height: 200%;
}
p {
font-size: 16px;
}
</style>
<body>
<p>AAA</p>
</body>
问:上述代码,p 标签的行高将会时多少?
答: 40px
【line-height如何继承?】
- 写具体数值,如30px,则继承该值(比较好理解)
- 写比例,如2/1.5,则继承该比例(比较好理解)
- 写百分比,如200%,则继承计算出来的值(考点)