小程序css样式不生效

当一个元素使用多个class时我们一般这样写:

<view class="box1 box2"></view>
<div class="box1 box2"></div>

假设box1里有个 margin:5px

  box2有个 margin:10px

那么浏览器会渲染哪个呢?

其实渲染优先级跟你使用的时候顺序没有关系(class="box1 box2"或者class="box2 box1")

跟你的css定义有关系:

.box2{
   margin:10px;      
}
.box1{
   margin:5px;      
}

在css定义里面,后者会覆盖前者

猜你喜欢

转载自www.cnblogs.com/momen/p/9258991.html