Solved Templates

media queries does not work

Asked by igorsv 4 years ago Last activity 3 years ago

HI friends i used to apply media queries to mobile wiew. Something has changed with bootstrap 5.

what ever i do i canot apply margin to logo on mobile view. Beffore i used this and it worked great:

@media screen and (max-width: 480px)
.header-sticky .logo-image {
    height: 50px;
    margin-top: 0px;
}

Can you help please

Accepted answer

Marked as the solution
Pavel
4 years ago · edited

This code shoud work, it works in chrome dev tools.

This code cannot work, as it has a syntactic error - the lack of figure brackets at the media query.

Ugur provided the correct code. I would add a more rigorous selector to it, as it is in template.css that successfully override it.

@media (max-width: 480px) {
  #sp-header.header-sticky .logo-image {
    height: 50px !important;
    margin-top: 0px;
  }
}

Or if your Header not sticky

@media (max-width: 480px) {
  #sp-header .logo-image {
    height: 50px !important;
    margin-top: 0px;
  }
}

19 more replies

Paul Frankowski Senior Staff
4 years ago · edited

Hi,
without link to URL hard to guess and help. But your CSS is not fully corect.

Ugur Uygur

It should be:

@media screen and (max-width: 480px) {
  .header-sticky .logo-image {
    height: 50px;
    margin-top: 0px;
  }
}
igorsv Asked this

For some reason it does not work i post it in custom code and no result.
site is https://vervo.eu/ee/
i try to change logo possition on mobile

igorsv Asked this
4 years ago · edited

This code shoud work, it works in chrome dev tools. but it none of them works in custom css

@media (max-width: 575px)
#sp-header .logo {
    height: 60px;
    margin-top: 10px;
}
igorsv Asked this

Hi Pavel in stiky it works all the time. bBut even your code does not change logo possiton.
I try to add margin-top:10px but no result

igorsv Asked this

Thanks Pavel this worked. Thanks


@media (max-width: 480px) {
  #sp-header .logo-image {
    height: 50px;
    margin-top: 10px;
  }
}
Pavel
4 years ago · edited

It works but this is not the right code to solve your task. margin-top: 10px; is a crutch.
Since you have increased the Header height you should also increase the height of all items that take the height of the Header.
The correct code will be such

@media (max-width: 480px) {
  #sp-header .logo {
      height: 80px;
    }
 #sp-header .logo-image {
    height: 50px;
  }
}

It lines all the elements in the center of the Header vertically.

igorsv Asked this

Pavel I am so thankful for your help. I wish i would be such pro. Realy thanks.

Pavel
4 years ago · edited

I wish i would be such pro.

Hi @igorsv. Not so difficult. Just need to study the behavior of the tool which use. When you change the height of the Header in the template settings, all other elements are aligned according to this height. But when you change the Header height through CSS, all other elements are crooked.

And here it is enough to ask yourself a question "Why is it going on?". Then open the browser code inspector and you will be able determine that the height value of the Header changed in the template settings is used as well in the line-height property for the menu item links, in the height property for the .logo (logo container) and in the height property for the #offcanvas-toggler.

After that you will know that fo changing the Header height via CSS you need also change the remaining items. Thus, the full code for changing the height of the Header will look like

#sp-header {
    height: 100px;
}
#sp-header .logo {
    height: 100px;
}
.sp-megamenu-parent > li > a, 
.sp-megamenu-parent > li > span {
    line-height: 100px;
}
#offcanvas-toggler {
    height: 100px;
}

And more compact record

#sp-header,
#sp-header .logo,
#offcanvas-toggler {
    height: 100px;
}
.sp-megamenu-parent > li > a, 
.sp-megamenu-parent > li > span {
    line-height: 100px;
}
Paul Frankowski Senior Staff

@Pavel , BIG thank you for helping user.

Log in to reply.