Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable css rules on mobile devices

I created a class in a wordpress css file

.leftfloat{ float:left; padding-right:10px; }

I use it in the posts to wrap text around images like so:

<div class ="leftfloat" > image code or ad code </leftfloat>

It's working on PC and mobile devices. However, I want to disable this float in mobile devices. So I did this:

There is already @media defined in the template, I just added .leftfloat {float: none;}

But when I check it, it's not disabling float on mobile devices.

@media screen and (max-width: 860px) {
        .leftfloat {float: none;}
}
@media screen and (max-width: 1020px) {
        .leftfloat {float: none;} }

@media screen and (max-width: 767px) {
        .leftfloat {float: none;}
}
@media screen and (max-width: 620px) {
        .leftfloat {float: none;} }

@media screen and (max-width: 420px) {
         .leftfloat {float: none;}
like image 222
tariqqqqqify Avatar asked Oct 28 '25 00:10

tariqqqqqify


1 Answers

Your complete CSS looks like:

.leftfloat{
  float:left;
  padding-right:10px;
}
   @media screen and (max-width: 860px) {
   .leftfloat {
     float: none;
   }
 }

 @media screen and (max-width: 1020px) {
   .leftfloat {
     float: none;
   }
 }

 @media screen and (max-width: 767px) {
   .leftfloat {
     float: none;
   }
 }

 @media screen and (max-width: 620px) {
   .leftfloat {
     float: none;
   }
 }

 @media screen and (max-width: 420px) {
   .leftfloat {
     float: none;
   }

As it stands, mobile gets the float: left from your original class because the media queries are all max-width. To set float: none at "mobile" sizes you need to reverse everything, (eg)

.leftfloat {
  float: none;
}

@media screen and (min-width: 420px) {
    .leftfloat {
      float: left;
    }
}
like image 59
Karl Dawson Avatar answered Oct 29 '25 13:10

Karl Dawson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!