简体   繁体   中英

Media queries issue with background URL

I have this html code of one div in my wordpress site.

<div class="bwpb-column bwpb-video-holder backgr bwpb-colwidth-4 " style="color: rgb(255, 255, 255); text-align: inherit; width: 100%; min-height: 923px; height: 628px; background: url(http://www.tfeditor.com/wp-content/uploads/2015/11/TFE.png) 50% 100% no-repeat rgb(255, 255, 255);"><div class="bwpb-overlay" style="background-color:rgba(255,255,255,0.01)"></div><div class="bwpb-column-inner" style="padding: 0px 15px; margin-top: 461.5px;"></div></div>

All im trying to do is to set some media queries that will change this image if there is a laptop or a tablet or smartphone.

After some research i've tested this code but its not working

(I've set the class of this div to .backgr)

@media (min-width: 1200px) {
  .backgr {
    background-image: url("http://www.tfeditor.com/wp-content/uploads/2015/11/TFE.png") !important;
  }

@media (max-width: 992px) {
  .backgr {
    background-image: url("http://www.tfeditor.com/wp-content/uploads/2015/11/XXL-02.png") !important;
  }
@media (max-width: 768px) {
  .backgr {
    background-image: url("http://www.tfeditor.com/wp-content/uploads/2015/11/XXL-03.png") !important;
  }


@media (max-width: 481px) {
  .backgr {
    background-image: url("http://www.tfeditor.com/wp-content/uploads/2015/11/XXL-04.png") !important;
  }

Does anyone have any suggestion of what should i put instead of my code so it will load other pics for phone/tablet/laptop ?

You forgot to put the closing bracket } on each media query. Should be like this:

@media (min-width: 1200px) {
  .backgr {
    background-image: url("http://www.tfeditor.com/wp-content/uploads/2015/11/TFE.png") !important;
  }
}  

@media (max-width: 992px) {
  .backgr {
    background-image: url("http://www.tfeditor.com/wp-content/uploads/2015/11/XXL-02.png") !important;
  }
}  
@media (max-width: 768px) {
  .backgr {
    background-image: url("http://www.tfeditor.com/wp-content/uploads/2015/11/XXL-03.png") !important;
  }
}

@media (max-width: 481px) {
  .backgr {
    background-image: url("http://www.tfeditor.com/wp-content/uploads/2015/11/XXL-04.png") !important;
  }
}  

after each media query you should close bracket ( } ) .

and it's good to use this:

@media only screen and (max-width:700px) {
  .backgr {
    background-image: url("http://www.tfeditor.com/wp-content/uploads/2015/11/XXL-02.png") !important;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM