T.Doe
T.Doe

Reputation: 2035

How to get a nav menu bar to scroll horizontally

I've got a nav bar with a few li tags that fall under each other when on a smaller screen size. I want the nav bar to remain the same height and scroll horizontally when on a smaller device screen but everything I'm trying is not working. Can someone shine a light on what is wrong here please!

HMTL:

<nav role="navigation" class="site-navigation main-navigation">
  <div class="menu">
    <ul>
      <li class="page_item page-item-40"><a href="http://localhost/property_abba/for-sale/">Buy</a></li>
      <li class="page_item page-item-41"><a href="http://localhost/property_abba/for-rent/">Rent</a></li>
      <li class="page_item page-item-7"><a href="http://localhost/property_abba/sell/">Sell</a></li>
      <li class="page_item page-item-9 current_page_item"><a href="http://localhost/property_abba/valuations/">Valuations</a></li>
      <li class="page_item page-item-15"><a href="http://localhost/property_abba/property-management/">Property Management</a></li>
      <li class="page_item page-item-11"><a href="http://localhost/property_abba/about-us/">About Us</a></li>
      <li class="page_item page-item-13"><a href="http://localhost/property_abba/contact-us/">Contact Us</a></li>
    </ul>
  </div>
</nav>

CSS:

@media screen and (max-width : 480px){
  div.menu ul {
    display: inline-block;
    max-height: 34px;
    overflow: auto;
    white-space: nowrap;
  }
  div.menu a {
    display: inline-block;
    text-align: center;
  }
}

But this currently is not working.

Upvotes: 0

Views: 1358

Answers (1)

Shital Marakana
Shital Marakana

Reputation: 2887

horizontal scroll menu mobile

 <style type="text/css">
    @media screen and (max-width : 480px){
      div.menu ul {
         display: inline-block;
         width: 85%;
        display: inline-block;
        padding-bottom:20px;
        white-space: nowrap;
        overflow-y: hidden;
        overflow-x: scroll; 
        -webkit-overflow-scrolling: touch; 
        -ms-overflow-style: -ms-autohiding-scrollbar;
      }
      div.menu li {
          display: inline-block; 
       }
      div.menu li a {
        text-align: center;
      }
    }
    </style>
    <nav role="navigation" class="site-navigation main-navigation">
      <div class="menu">
        <ul>
          <li class="page_item page-item-40"><a href="http://localhost/property_abba/for-sale/">Buy</a></li>
          <li class="page_item page-item-41"><a href="http://localhost/property_abba/for-rent/">Rent</a></li>
          <li class="page_item page-item-7"><a href="http://localhost/property_abba/sell/">Sell</a></li>
          <li class="page_item page-item-9 current_page_item"><a href="http://localhost/property_abba/valuations/">Valuations</a></li>
          <li class="page_item page-item-15"><a href="http://localhost/property_abba/property-management/">Property Management</a></li>
          <li class="page_item page-item-11"><a href="http://localhost/property_abba/about-us/">About Us</a></li>
          <li class="page_item page-item-13"><a href="http://localhost/property_abba/contact-us/">Contact Us</a></li>
        </ul>
      </div>
    </nav>

Upvotes: 1

Related Questions