1

This is my CSS media query code in header.html file. i write css media query in html file.

<style type="text/css">

@media (min-width:100px ) and (max-width:480px ){
    .background-color-sec-1-images {
        background-image: url("localhost/set/img/img1.jpg");
        background-repeat:no-repeat; 
        background-size:100% 100%;
    }        
}
@media (min-width:480px ) and (max-width:768px ){
    .background-color-sec-1-images {
        background-image: url("localhost/set/img/img1.jpg");
        background-repeat:no-repeat; 
        background-size:100% 100%;
    }        
}
@media (min-width:768px ) and (max-width:1200px ){
    .background-color-sec-1-images {
        background-image: url("localhost/set/img/img1.jpg");
        background-repeat:no-repeat; 
        background-size:100% 100%;
    }        
}      
</style>

This CSS is not working.

When i write css like this is working fine.

    <style type="text/css">

@media (min-width:100px ){
    .background-color-sec-1-images {
        background-image: url("localhost/set/img/img1.jpg");
        background-repeat:no-repeat; 
        background-size:100% 100%;
    }        
}
@media (min-width:480px ){
    .background-color-sec-1-images {
        background-image: url("localhost/set/img/img1.jpg");
        background-repeat:no-repeat; 
        background-size:100% 100%;
    }        
}
@media (min-width:768px ){
    .background-color-sec-1-images {
        background-image: url("localhost/set/img/img1.jpg");
        background-repeat:no-repeat; 
        background-size:100% 100%;
    }        
}      
</style>

But This is overwrite css. so this is not working for me.

but why not working @media (min-width:100px) and (max-width:400px) query?

thank you.

9
  • try min-width:481px and try min-width:769px in the second and third. Commented Apr 2, 2014 at 14:59
  • i try not but working thank's. Commented Apr 2, 2014 at 15:01
  • Have you tried adding http:// to your paths? Commented Apr 2, 2014 at 15:04
  • The CSS seems fine jsfiddle.net/8V3L7, background images are swapping out for me. Are you certain it's the media queries that are causing the problem? Can you provide more context for this? Commented Apr 2, 2014 at 15:06
  • @Serlite i mention that the i write css in html page so that not working? Commented Apr 2, 2014 at 15:08

2 Answers 2

1

edited: in pure css, you have to declare your media and INSIDE put your conditions.

@media print { // rule (1)
  #anId{ 
    //something here
   }
  @media (max-width: 12cm) { // rule (2)
    //something here
  }
}

here docs

so first of your rules can be:

@media screen{
  @media (min-width:100px ) and (max-width:480px ){
    .background-color-sec-1-images {
        background-image: url("localhost/set/img/img1.jpg");
        background-repeat:no-repeat; 
        background-size:100% 100%;
    }        
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

you must declare which media you are using:

http://www.w3schools.com/css/css_mediatypes.asp

so in your case use as follows:

@media screen (min-width:100px ) {
/* your styling goes here */
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.