0

I'm a little bit confused because I'm used to do some CSS using media queries... I never had this problem before. Only the first media query is working well... I have few media queries working on specifics sizes like this :

/* - IPAD LANDSCAPE - */

@media screen and (max-width: 1024px) and (orientation: landscape){
  header{
    background-size: 28vw 30vh, 34vw 38vh;
    background-position: right 24vw top 3.5vh, right 21vw top 1vh;
  }
  header object{
    left:16vw;
    width:18vw !important;
  }
  header p{
    font-size:14px;
    top:16vh;
    left:-2vw;
  }
}

/* - IPAD PORTRAIT - */

@media screen and (max-width: 768px) and (orientation: portrait){
  header{
    background-size: 28vw 30vh, 34vw 38vh;
    background-position: right 28vw top 3.5vh, right 17vw top 1vh;
  }
  header object{
    left:10vw;
    width:24vw !important;
  }
  header p{
    font-size:20px;
    top:10vh;
    left:-2vw;
  } 
}

/* - PHONE LANDSCAPE - */

@media screen and (max-width: 750px) and (orientation: landscape){
  /*...*/
}

/* - PHONE PORTRAIT - */

@media screen and (max-width: 450px) and (orientation: portrait){
  /*...*/
}

I tried with and without the orientation parameter... I can't even figure out why my code isn't working well... I watched few topics on this but it didn't help me...

Thanks for helping :-)

EDIT:

I'm using Bootstrap for the first time, does it change something on media queries ?

EDIT 2:

I saw something like @media screen and (max-width:screen-sm-max) when we use Bootstrap, should I use this instead of pxvalue ? I think it will still the same...

3
  • jsfiddle.net example?
    – Paul C
    Jun 7, 2016 at 14:04
  • Media queries order matters too, so check and arrange it as per your requirement. Jun 7, 2016 at 14:10
  • I'm working on a huge code and I can't really reproduce the same thing... But maybe you know if it's a "background-size" resizing problem ? or as I edited a bootstrap problem ? I will try to code a similar code on jsfiddle.net @KaushalSuthar : I thought it was the highest width first then the others because the last media query has better priority
    – triskheal
    Jun 7, 2016 at 14:10

1 Answer 1

2

Try to put the smallest @media queries width block of code first.

/* - PHONE PORTRAIT - */
@media screen and (max-width: 450px) and (orientation: portrait){
  /*...*/
}

/* - PHONE LANDSCAPE - */
@media screen and (max-width: 750px) and (orientation: landscape){
  /*...*/
}

/* - IPAD PORTRAIT - */
@media screen and (max-width: 768px) and (orientation: portrait){
  header{
    background-size: 28vw 30vh, 34vw 38vh;
    background-position: right 28vw top 3.5vh, right 17vw top 1vh;
  }
  header object{
    left:10vw;
    width:24vw !important;
  }
  header p{
    font-size:20px;
    top:10vh;
    left:-2vw;
  } 
}

/* - IPAD LANDSCAPE - */
@media screen and (max-width: 1024px) and (orientation: landscape){
  header{
    background-size: 28vw 30vh, 34vw 38vh;
    background-position: right 24vw top 3.5vh, right 21vw top 1vh;
  }
  header object{
    left:16vw;
    width:18vw !important;
  }
  header p{
    font-size:14px;
    top:16vh;
    left:-2vw;
  }
}

It solved this type of problem for me. Boostrap doc is following this structure too. (here @screen-sm-min are variables that you can set thank to LESS/SASS, but you cant replace it by fixed number)

/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */

/* Small devices (tablets, 768px and up) */
@media (min-width: @screen-sm-min) { ... }

/* Medium devices (desktops, 992px and up) */
@media (min-width: @screen-md-min) { ... }

/* Large devices (large desktops, 1200px and up) */
@media (min-width: @screen-lg-min) { ... }

Personally I use something like that if it could help you :

@media (max-width:767px) {}

@media (max-width:767px) and (orientation:landscape) {}

@media (min-width:768px) and (max-width:991px) {}
8
  • I tried twice, and I just tried again now, it doesn't work... I just removed the orientation parameter, still the same :/ Does the min-widthchange a lot the code interpretation ?
    – triskheal
    Jun 7, 2016 at 14:28
  • An important thing it's also to keep the same or even a more strict selector. You can't make header.myheader#myheader{ display:block} and expect that your @media queriesxxxx { header { display:none; } } works. header.myheader will override header because of a more specific selector. copy/paste same css selector. Keep in mind that bootsrap could override your css too. Jun 7, 2016 at 14:31
  • My selector are both the same it's ok for that. And yeah that was my question on my edit post : does bootstrap edit media queries ? If yes, why my the media query for 1024px is working well but not others ? Same if I make it first or last on media query place in my code...
    – triskheal
    Jun 7, 2016 at 14:38
  • We'll need a jsfiddle.net or things like that ;) Jun 7, 2016 at 15:01
  • On developper tools on chrome, it shows me that it takes media screen 1024px, with all device with width <= 1024px... It totally ignore the others... I don't know why you really need a jsfiddle exemple ? :P It will be hard to reproduce the same way
    – triskheal
    Jun 7, 2016 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.