css样式中的百分比都是相对于谁的?
idth、height(正常定位)
width 和 height 的百分比是分别根据父级元素块的宽度和高度来计算的。
相对定位的 top、left
1 position: relative; 2 top: 100%; 3 left: 100%;
top 和 left 的百分比是分别根据父级元素块的高度和宽度来计算的。
绝对定位的 top、left、width、height
1 position: absolute; 2 top: 50%; 3 left: 50%; 4 5 width: 100%; 6 height: 100%;
top、height 和 left、width 的百分比是分别根据包含它的第一个不是 static 定位的元素的高度和宽度来计算的。
固定定位的 top、left
position: fixed;
top: 50%;
left: 50%;
top 和 left 的百分比是分别根据浏览器视口的高度和宽度来计算的。
translate
1 transform: translate(-50%, -50%);
translate 是根据自身的宽高来计算的。
margin-top, margin-left,padding-top, padding-left
1 margin-top: 50%; 2 margin-left: 50%;
相对于父级元素块的宽度。
border-radius
1 border-radius: 50%;
相对于自身。
background-size
1 background-size: 100% 100%;
相对背景区的宽高。
浙公网安备 33010602011771号