D
D
Diversia2016-10-04 11:55:16
css
Diversia, 2016-10-04 11:55:16

How to make the Bootstrap menu not go beyond the window borders?

Hello.
The site menu is made in Bootstrap. The drop-down list of the menu item, which is located to the right of the window border, causes horizontal scrolling:
de931cf09ed74bb69db6a3bd6ef79b7c.png
The code is standard:

<div class="navbar navbar-default navbar-static-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Меню</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Фирма</a>
    </div>
    <div class="navbar-collapse collapse"> 
      <ul class="nav navbar-nav">
        <!-- здесь много пунктов меню -->
        <li class="dropdown"><a href="#" class="dropdown-toggle" role="button" aria-haspopup="true" aria-expanded="false">Выпадающее меню у края окна</a>
          <ul class="dropdown-menu">
            <li><a href="#">Залезает за край окна</a></li>
            <li><a href="#">Залезает за край окна</a></li>
            <li><a href="#">Залезает за край окна</a></li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
</div>

Please help me fix it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
surid, 2016-10-04
@surid

codepen.io/surid/pen/QKOaAo

M
Mikhail Enikeev, 2016-10-04
@miha872287

Try it!

<div class="navbar navbar-default navbar-static-top" role="navigation">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Меню</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Фирма</a>
        </div>
        <div class="navbar-collapse collapse"> 
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Главная <span class="sr-only"></span></a></li>
            <li><a href="#">О нас</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Выпадающее меню у края окна<span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><a href="#">Залезает за край окна</a></li>
                <li><a href="#">Залезает за край окна</a></li>
                <li><a href="#">Залезает за край окна</a></li>
                
            </ul>
        </li>
    </ul>
</div>
</div>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question