Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap 4 navbar sticky only on mobile

I have this (haml):

  %body
    .container
      %nav.navbar.sticky-top.navbar-expand-md.navbar-light.bg-light

is there a bootstrap only way to make this navbar sticky top only when on mobile (< lg)?

like image 811
John Smith Avatar asked Oct 17 '22 05:10

John Smith


1 Answers

You can force the navbar to stick to the top on mobile only using a media query.

Change the max-width to your desired maximum width

@media (max-width: 1200px) {
  body {
    margin-top: 50px;
  }

  .navbar{
    position: fixed;
    right: 0;
    left: 0;   
    border-radius: 0;
    top: 0;
  }      
}

Hope this helps.

like image 182
TidyDev Avatar answered Oct 23 '22 00:10

TidyDev