Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

html - How can i make the navbar menu options to move in the right side?

Kindly help and let me know where am i making the mistake as i can not make the options in the navbar go into the right side. Here i am sharing the code.

<div>
        <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top" style="padding-left: 40px; padding-right: 40px;">
            
            <div style="float: left;">
                <a class="navbar-brand" href="homePage.php">Job Portal</a>
            </div>
            
            <div class="topnav-right" style="float: right;">
                <a href="homePage.php">
                    <button class="btn btn-outline-success" type="button" >
                        Home
                    </button>
                </a>
                
                <a href="signinPageOfJobSeekers.php">   
                    <button class="btn btn-outline-success" type="button">
                        Sign In or Sign up
                    </button>
                </a>    

                <button class="btn btn-outline-success" type="button">
                    Contact Us
                </button>

                <?php if(!empty($_SESSION['userName'])){ ?>
                        <a href="logOut.php">
                            <button class="btn btn-outline-success" type="button">
                                Log Out
                            </button>
                        </a>
                
                <?php   } ?>

            </div>
                
        </nav>

    </div>
question from:https://stackoverflow.com/questions/65545566/how-can-i-make-the-navbar-menu-options-to-move-in-the-right-side

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your code is not enough to give you a perfect solution. However, here is my shot:

I assume that the wrapper container <div> ... </div> you have spans 100% of the viewport width? If this is the case, you can add the following style attribute:

<div style="display: flex; justify-content: flex-end;">
   <nav>
      // rest of the HTML code in your example
   </nav>
</div>

Of course, for a cleaner solution, instead of adding an inline style attribute, you can add a CSS class and style it in a separate stylesheet file or style tag in your document <head>:

<div class="nav-wrapper">
   <nav>
      // rest of the HTML code in your example
   </nav>
</div>

and then in your CSS declarations

.navWrapper {
  display: flex;
  justify-content: flex-end;
}

Alternative solution

If you are okay with your navigation overlapping the rest of the page content, you can always position: fix it. This way it would be taken out of the document flow and overlayed on top of the other HTML elements on your page. Here is the CSS needed:

.nav-wrapper {
  position: fixed;
  top: 0px;
  right: 0px;
  z-index: 999; // <- increase this value if any elements are on top of your nav
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...