关于css中em和百分数的区别

使用百分数的时候,子栏目的所有属性(width、height、margin、padding等)都是根据父级栏目的宽高属性来设置的,如果是使用em的时候,子栏目都是根据他的父级栏目的字体大小设置的

.sub1{

        width: 150%;

        height: 150%;

        background-color: #2187E7;

        }

继承的是父级的width和height!所以sub1的宽度和高度最后应该是150px;

em他是根据父级的:font-size属性值来定义的,当body的font-size:16px时

sub2的宽度高度其实就只有16px!

猜你喜欢

转载自570109268.iteye.com/blog/2401480
今日推荐