Float:左侧不会被媒体查询删除

Kok*_*oko 2 html css responsive-design

我在我的CSS中使用Float,但是如果用户在小屏幕上我想要取消它.我的CSS与媒体查询工作正常,除了仍然应用"float:left"属性,即使在声明不应该使用它之后:

/* floating some buttons */
#n2, #n3 {
  float:right;
}

/* but this is not removing the float: */
@media only screen and (min-width : 150px) and (max-width : 780px) {
  #n2, #n3 {
    clear: both !important;
  }
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能在某些情况下申请"浮动"?

Has*_*ami 12

正如我在评论中指出的那样,当您要删除时float,您需要将值设置为none:

/* but this is not removing the float: */
@media only screen and (min-width : 150px) and (max-width : 780px) {
  #n2, #n3 {
    float: none;
  }
}
Run Code Online (Sandbox Code Playgroud)

JSBin演示


Mag*_*aar 6

答案:

@media only screen and (min-width : 150px) and (max-width : 780px) {
      #n2, #n3 {
        float:none;
      }
    }
Run Code Online (Sandbox Code Playgroud)

说明:

你需要设置float:none重置float:left