bootstrap responsive navbar to place elements on a new row when width does not fit all elements











up vote
0
down vote

favorite












Having the following navbar in boostrap 4:



<nav class="navbar navbar-expand text-light bg-secondary">
<ul class="navbar-nav">
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">A</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">B</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">C</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">D</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">E</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">F</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">G</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">H</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">I</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">J</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">K</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">L</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">M</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">N</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">O</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">P</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Q</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">R</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">S</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">T</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">U</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">V</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">W</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">X</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Y</a></li>
<li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Z</a></li>
</ul>
</nav>


On large screen, content looks good since all elements are shown. However, on small size screens, only the starting elements are shown since they fit in the width of the screen, while the remaining ones are hidden outside the viewport and a user has to scroll right to see them.



How to style this navbar in a responsive way, when the screen size is small, let the elements that do not fit, go into a new row below the shown elements. Since there are more than 12 elements, I could not use the bootstrap grid concept to solve it. In addition, I count on having a dynamic number of elements and want the content to be center displayed.










share|improve this question


























    up vote
    0
    down vote

    favorite












    Having the following navbar in boostrap 4:



    <nav class="navbar navbar-expand text-light bg-secondary">
    <ul class="navbar-nav">
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">A</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">B</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">C</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">D</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">E</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">F</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">G</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">H</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">I</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">J</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">K</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">L</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">M</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">N</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">O</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">P</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Q</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">R</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">S</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">T</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">U</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">V</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">W</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">X</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Y</a></li>
    <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Z</a></li>
    </ul>
    </nav>


    On large screen, content looks good since all elements are shown. However, on small size screens, only the starting elements are shown since they fit in the width of the screen, while the remaining ones are hidden outside the viewport and a user has to scroll right to see them.



    How to style this navbar in a responsive way, when the screen size is small, let the elements that do not fit, go into a new row below the shown elements. Since there are more than 12 elements, I could not use the bootstrap grid concept to solve it. In addition, I count on having a dynamic number of elements and want the content to be center displayed.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Having the following navbar in boostrap 4:



      <nav class="navbar navbar-expand text-light bg-secondary">
      <ul class="navbar-nav">
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">A</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">B</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">C</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">D</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">E</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">F</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">G</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">H</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">I</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">J</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">K</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">L</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">M</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">N</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">O</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">P</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Q</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">R</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">S</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">T</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">U</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">V</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">W</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">X</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Y</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Z</a></li>
      </ul>
      </nav>


      On large screen, content looks good since all elements are shown. However, on small size screens, only the starting elements are shown since they fit in the width of the screen, while the remaining ones are hidden outside the viewport and a user has to scroll right to see them.



      How to style this navbar in a responsive way, when the screen size is small, let the elements that do not fit, go into a new row below the shown elements. Since there are more than 12 elements, I could not use the bootstrap grid concept to solve it. In addition, I count on having a dynamic number of elements and want the content to be center displayed.










      share|improve this question













      Having the following navbar in boostrap 4:



      <nav class="navbar navbar-expand text-light bg-secondary">
      <ul class="navbar-nav">
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">A</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">B</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">C</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">D</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">E</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">F</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">G</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">H</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">I</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">J</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">K</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">L</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">M</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">N</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">O</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">P</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Q</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">R</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">S</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">T</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">U</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">V</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">W</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">X</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Y</a></li>
      <li class="nav-item ml-1 mr-1"><a href="#" class="btn btn-sm btn-outline-light">Z</a></li>
      </ul>
      </nav>


      On large screen, content looks good since all elements are shown. However, on small size screens, only the starting elements are shown since they fit in the width of the screen, while the remaining ones are hidden outside the viewport and a user has to scroll right to see them.



      How to style this navbar in a responsive way, when the screen size is small, let the elements that do not fit, go into a new row below the shown elements. Since there are more than 12 elements, I could not use the bootstrap grid concept to solve it. In addition, I count on having a dynamic number of elements and want the content to be center displayed.







      html css twitter-bootstrap






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 18:16









      EddyG

      3661420




      3661420
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You can achieve this using flexbox, by default the navbar-nav class has a flex-wrap: no-wrap, that means that the nav items will never go below, what you can do to fix this is



          .navbar-nav{
          flex-wrap: wrap;
          }


          Instead of no wrap, you can set flex-wrap: wrap;, and that should work, now you need to style the nav-items for this to look good, hope this help you.



          Here you have an article that will help you to understand how flexbox work



          And to align content center, add justify-content-center class to nav element



          <nav class="navbar navbar-expand text-light bg-secondary justify-content-center">





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242006%2fbootstrap-responsive-navbar-to-place-elements-on-a-new-row-when-width-does-not-f%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            You can achieve this using flexbox, by default the navbar-nav class has a flex-wrap: no-wrap, that means that the nav items will never go below, what you can do to fix this is



            .navbar-nav{
            flex-wrap: wrap;
            }


            Instead of no wrap, you can set flex-wrap: wrap;, and that should work, now you need to style the nav-items for this to look good, hope this help you.



            Here you have an article that will help you to understand how flexbox work



            And to align content center, add justify-content-center class to nav element



            <nav class="navbar navbar-expand text-light bg-secondary justify-content-center">





            share|improve this answer



























              up vote
              1
              down vote



              accepted










              You can achieve this using flexbox, by default the navbar-nav class has a flex-wrap: no-wrap, that means that the nav items will never go below, what you can do to fix this is



              .navbar-nav{
              flex-wrap: wrap;
              }


              Instead of no wrap, you can set flex-wrap: wrap;, and that should work, now you need to style the nav-items for this to look good, hope this help you.



              Here you have an article that will help you to understand how flexbox work



              And to align content center, add justify-content-center class to nav element



              <nav class="navbar navbar-expand text-light bg-secondary justify-content-center">





              share|improve this answer

























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                You can achieve this using flexbox, by default the navbar-nav class has a flex-wrap: no-wrap, that means that the nav items will never go below, what you can do to fix this is



                .navbar-nav{
                flex-wrap: wrap;
                }


                Instead of no wrap, you can set flex-wrap: wrap;, and that should work, now you need to style the nav-items for this to look good, hope this help you.



                Here you have an article that will help you to understand how flexbox work



                And to align content center, add justify-content-center class to nav element



                <nav class="navbar navbar-expand text-light bg-secondary justify-content-center">





                share|improve this answer














                You can achieve this using flexbox, by default the navbar-nav class has a flex-wrap: no-wrap, that means that the nav items will never go below, what you can do to fix this is



                .navbar-nav{
                flex-wrap: wrap;
                }


                Instead of no wrap, you can set flex-wrap: wrap;, and that should work, now you need to style the nav-items for this to look good, hope this help you.



                Here you have an article that will help you to understand how flexbox work



                And to align content center, add justify-content-center class to nav element



                <nav class="navbar navbar-expand text-light bg-secondary justify-content-center">






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 10 at 18:52









                EddyG

                3661420




                3661420










                answered Nov 10 at 18:37









                MartinBA

                70513




                70513






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242006%2fbootstrap-responsive-navbar-to-place-elements-on-a-new-row-when-width-does-not-f%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues