Is there a way to position this navbar menu on the right side of the website?

Does anyone know how to align the navbar menu to the right side?

I've been attempting to float it right without success. What would be the recommended solution?

I have tried multiple approaches but haven't achieved any results yet. Can someone kindly help me resolve this issue?

Below is my code snippet:

<html>

    <head>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c5a7aaaab1b6b1b7a4b585f0ebf4ebf4">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"
            integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">

        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1e7c71716a6d6a6c7f6e33777d71706d5e2f302b302e">[email protected]</a>/font/bootstrap-icons.css">

        <title>TechSite</title>

        <style>
            .navbar-brand{
                font-size: 2rem;
            }
            ul.navbar-nav {
               font-size: 1.15rem;
            }
            .nav-link {
                padding: .3rem 1rem;
                color: white;
            }

            .nav-link:hover {
                color: white;
            }

            button.navbar-toggler {
                color: white;
            }

            p {
                color: gray;
            }
        </style>

    </head>

    <body>

        <!-- navbar -->

        <nav class="navbar navbar-expand-lg  bg-dark fixed-top">

            <div class="container-fluid">

                <a class="navbar-brand" href="#" style="color: red;">
                    TechSite
                </a>

                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                    aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon" style="color: white;"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav float-end">
                        <li class="nav-item">
                            <a class="nav-link active rounded" aria-current="page" href="#"
                                style="color: rgb(173, 173, 173);border: 1px solid wheat;">
                                Home
                            </a>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
                                data-bs-toggle="dropdown" aria-expanded="false">
                                Services
                            </a>
                            <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                                <li><a class="dropdown-item" href="#">App Development</a></li>
                                <li><a class="dropdown-item" href="#">Game Development</a></li>
                                <li><a class="dropdown-item" href="#">Web Development</a></li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" style="color: white;">About</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" style="color: white;">Contact</a>
                        </li>
                    </ul>
                </div>

            </div>

        </nav>

    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="53313c3c27202721322313667d627d62">[email protected]</a>/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ"
        crossorigin="anonymous"></script>

    </body>

    </html>

Would employing Bootstrap 5 offer a more effective solution for this issue?

Answer №1

When working in the flex system, you can align your option menu to the right side by giving the container navbar-collapse the class justify-content-center.

Make sure to update your HTML code with the following:

<nav class="navbar navbar-expand-lg  bg-dark fixed-top">

  <div class="container-fluid">

      <a class="navbar-brand" href="#" style="color: red;">
          TechSite
      </a>

      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
          aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon" style="color: white;"></span>
      </button>

      <div class="collapse navbar-collapse justify-content-center" id="navbarNav">
          <ul class="navbar-nav float-end">
            <li class="nav-item">
              <a class="nav-link active rounded" aria-current="page" href="#"
                  style="color: rgb(173, 173, 173);border: 1px solid wheat;">
                  Home
              </a>
          </li>
              <li class="nav-item dropdown">
                  <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
                      data-bs-toggle="dropdown" aria-expanded="false">
                      Services
                  </a>
                  <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                      <li><a class="dropdown-item" href="#">App Development</a></li>
                      <li><a class="dropdown-item" href="#">Game Development</a></li>
                      <li><a class="dropdown-item" href="#">Web Development</a></li>
                  </ul>
              </li>
              <li class="nav-item">
                  <a class="nav-link" href="#" style="color: white;">About</a>
              </li>
              <li class="nav-item">
                  <a class="nav-link" href="#" style="color: white;">Contact</a>
              </li>
              
          </ul>
      </div>

  </div>

</nav>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a syntax error when trying to parse a local storage object?

I've been exploring ways to store random numbers generated by Math.random. I've come up with a solution where I save the numbers in an array, which is then stored in localStorage. My goal is to append each new array of numbers whenever Math.rando ...

Incorporate variable key-value pairs into a JavaScript array or object

Is it possible to add a key value pair to an existing JavaScript associative array using a variable as the key? I need this for JSON encoding and prefer a simple solution over using plugins or frameworks. ary.push({name: val}); In the above code snippet, ...

Verifying with VueJS and Jest: How to test if a component's method calls an imported function

I've created a VueJS 2 component that has the following structure: <template> <div> <button @click="onFavorite"> Add to favorites </button> </div> </template> <script> import { tra ...

Ways to expand CRA ESLint guidelines using the EXTEND_ESLINT environmental variable

Facebook's Create React App (CRA) recently introduced a new feature allowing users to customize the base ESLint rules. Recognizing that some cases may require further customization, it is now possible to extend the base ESLint config by setting the ...

Using @media queries for mobile and desktop: preventing desktop from displaying mobile styles

I have been working on redesigning a website for mobile using only CSS. I set up media queries to deliver the appropriate CSS for desktop and mobile devices. However, I noticed that when resizing the browser to under 855 pixels, some of the mobile CSS is ...

The HTML and JavaScript implementation of the Game of Life is experiencing technical difficulties

I attempted to create my own version of the Game of Life using HTML canvas and JavaScript. With the aid of various online tutorials, I was able to write a piece of code that I am still confident in. However, upon launching the HTML page in the browser and ...

Exploring the power of Angular JS promises through ng-repeat

My current project involves fetching latitude and longitude coordinates from a postcode using an API, then utilizing those coordinates to retrieve data on street level crimes near that location on a specific date through the UK police API. However, I have ...

Retrieve isolated scope of directive from transcluded content

I am not certain if it is possible, but I am essentially looking for a reverse version of the '&' isolate scope in AngularJS. You can check out this Plunkr to see an example. In essence, I have created a custom directive that provides some r ...

Using explode() in PHP to read a text file and extract desired sections of text

I am faced with a challenge involving two text files - users.txt and schedule.txt. The content of the schedule.txt file is structured as follows: 0 1 2 2013-04-11^12:00|4:00|14:00 3 4 5 6 2013-07-21^10:00|15:00|18: ...

What is the best way to align a series of divs vertically within columns?

Struggling to find the right words to ask this question has made it difficult for me to locate relevant search results. However, I believe a picture is worth a thousand words so...https://i.stack.imgur.com/LfPMO.png I am looking to create multiple columns ...

I'm completely baffled as to why the client console is unable to locate my JS file

I have a question that may seem basic, so please bear with me! I'm having trouble adding a js file to an html page and it seems to be related to the file path. In my HTML page, I have this code to link the file: <script src="../src/utils/mapbo ...

Issue encountered: The differ cannot recognize the provided object '[object Object]', which is of type 'object'. NgFor is limited to binding Iterables only

I have been following a tutorial on Ionic created by Paul Halliday, focusing on a shopping list project that utilizes Firebase and Angular. However, I am encountering an error every time I try to run the application: Error: Uncaught (in promise): Error: ...

Bringing in features in Vue.js

Looking to incorporate a utils service into my Vue component: import utilities from './utils'; export default { name: 'grid', props: { 'gridInit': { type: Object, require: true }, 'gridDataInit&a ...

Can you define the "tab location" in an HTML document using React?

Consider this component I have: https://i.stack.imgur.com/rAeHZ.png React.createClass({ getInitialState: function() { return {pg: 0}; }, nextPage: function(){ this.setState({ pg: this.state.pg+1} ) }, rend ...

Discover the ultimate solution to disable JSHint error in the amazing Webstorm

I am encountering an error with my test files. The error message states: I see an expression instead of an assignment or function call. This error is being generated by the Chai library asserts. Is there a way to disable this warning in Webstorm? It high ...

The full width of the div exceeds the parent's width, resulting in the box size being ineffective

I'm experiencing an issue where my cover is wider than my element and content. It seems to be covering the gunter, but I've tried using background-clip: content-box; and box-sizing: border-box;, which haven't resolved the problem. I also wan ...

Error: Mongoose Cannot Save Data to an Uninitialized Object

Let me explain my current situation: I had a basic Schema in place with an object called commands, initially set to {}. commands:{} While trying to add a document to the database, I iterated through a file of commands and added them to the object using t ...

Ensuring Consistency in Object Size When Switching Between Perspective and Orthographic Cameras

Struggling to toggle between Perspective and Orthographic cameras in my script. I need objects at certain depths to maintain their projection size. I've reached a point of confusion when trying to understand the geometry... Can anyone recommend a sim ...

Include a legal disclaimer on a website comprised of individual pages

The website at was uniquely crafted by hand, without the use of platforms like Wordpress or any PHP-type databases. Upon its creation over 15 years ago, a legal notice was not initially included on the website. Now, there is a desire to add a link to a l ...

Using JavaScript to generate JSON data in a plain text format rather than using HTML

I have a snippet of code that retrieves the user's location every 5 seconds. <div id="geo" onLoad=""></div> <script> function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPo ...