What is the best way to right-align navigation using bootstrap?

We are struggling to align our navigation items to the right side of our page. Despite using a container class and align-items-end, we have not been successful in achieving this. We must confess that this section is somewhat hastily put together, and we do not fully comprehend everything happening within it. Our goal is to create a top section on our page with a cover image, navigation aligned to the right inside the container, a heading, and two buttons. Additionally, we require our navigation to collapse at the small (mobile) breakpoint.

This is our design concept from Photoshop, showcasing what we aim for our final design to resemble.

Currently, this is how our code is rendering.

Where are we making mistakes?

.cover {
  min-height: 500px;
  background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url(img/moco-trucks.png);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  color: #fff;
  position: relative;
}

.navbar-dark .navbar-nav .nav-link {
  color: #fff;
}

.navbar-dark:hover,
.navbar-dark:focus,
.navbar-dark:active {
  color: rgba(199, 84, 40, 1)
}

.nav-item,
.nav-link {
  color: #fff;
  text-transform: uppercase;
}

.nav-pills .nav-link.active,
.nav-pills .show>.nav-link {
  color: #fff;
  background-color: #c75428;
}

.nav-pills .nav-link.active:hover,
.nav-pills .show>.nav-link {
  color: #fff;
  background-color: #a64723;
}

.nav-link:hover,
.nav-link:focus,
.nav-link:active {
  color: #c75428;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec8e8383989f989e8d9cacd8c2dac2dc">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">

<!-- container with bg img -->
<div class="cover">
  <div class="container justify-content-end">
    <!-- NAV Here -->
    <nav class="navbar navbar-expand-sm navbar-dark" aria-label="responsive navbar">
      <a class="navbar-brand" href="index.html"><img src="img/the-other-side-moving-storage-color-white.png" width="75%" height="75%"></a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#responsive-navbar" aria-controls="responsive-navbar" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
      <div class="collapse navbar-collapse" id="responsive-navbar">
        <ul class="navbar-nav me-auto mb-2 mb-sm-0">
          <li class="nav-item">
            <a class="nav-link" href="denver-moving-services.html">Moving</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="denver-storage-company.html">Storage</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="receiving-and-delivery.html">Furniture Delivery</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="about-us.html">About</a>
          </li>
          <li class="nav-item">
            <a href="free-estimate.html"><button class="btn btn-tosa" type="submit">Free Estimate</button></a>
          </li>
        </ul>
      </div>
    </nav>
  </div>
  <!-- Nav end -->
  <!-- FS Hero -->
  <div class="container-xl mb-4">
    <div class="row text-center">
      <div class="col-12">
        <h1 class="py-5">Denver Moving and Storage</h1>
        <a href="free-estimate.html"><button type="button" class="btn btn-tosa mx-3">Free Estimate</button></a>
        <a href="about-us.html"><button type="button" class="btn btn-outline-tosa mx-3">Our Story</button></a>
      </div>
    </div>
  </div>
  <!-- End FS Hero -->
</div>
<!-- End Cover -->

Answer №1

I have implemented the justify-content-end property to the link wrapper.

For more information on flex utilities, check out this resource.

.cover {
  min-height: 500px;
  background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url(img/moco-trucks.png);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  color: #fff;
  position: relative;
}

.navbar-dark .navbar-nav .nav-link {
  color: #fff;
}

.navbar-dark:hover,
.navbar-dark:focus,
.navbar-dark:active {
  color: rgba(199, 84, 40, 1)
}

.nav-item,
.nav-link {
  color: #fff;
  text-transform: uppercase;
}

.nav-pills .nav-link.active,
.nav-pills .show>.nav-link {
  color: #fff;
  background-color: #c75428;
}

.nav-pills .nav-link.active:hover,
.nav-pills .show>.nav-link {
  color: #fff;
  background-color: #a64723;
}

.nav-link:hover,
.nav-link:focus,
.nav-link:active {
  color: #c75428;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6d0f0202191e191f0c1d2d59435b435d">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">

<!-- container with bg img -->
<div class="cover">
  <div class="container">
    <!-- NAV Here -->
    <nav class="navbar navbar-expand-sm navbar-dark d-flex" aria-label="responsive navbar">
      <a class="navbar-brand" href="index.html"><img src="https://via.placeholder.com/60" width="75%" height="75%"></a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#responsive-navbar" aria-controls="responsive-navbar" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
      <div class="collapse navbar-collapse justify-content-end" id="responsive-navbar">
        <ul class="navbar-nav me-auto mb-2 mb-sm-0">
          <li class="nav-item">
            <a class="nav-link" href="denver-moving-services.html">Moving</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="denver-storage-company.html">Storage</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="receiving-and-delivery.html">Furniture Delivery</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="about-us.html">About</a>
          </li>
          <li class="nav-item">
            <a href="free-estimate.html"><button class="btn btn-tosa" type="submit">Free Estimate</button></a>
          </li>
        </ul>
      </div>
    </nav>
    <!-- Nav end -->
  </div>
  <!-- FS Hero -->
  <div class="container-xl mb-4">
    <div class="row text-center">
      <div class="col-12">
        <h1 class="py-5">Denver Moving and Storage</h1>
        <a href="free-estimate.html"><button type="button" class="btn btn-tosa mx-3">Free Estimate</button></a>
        <a href="about-us.html"><button type="button" class="btn btn-outline-tosa mx-3">Our Story</button></a>
      </div>
    </div>
  </div>
  <!-- End FS Hero -->
</div>
<!-- End Cover -->

Answer №2

I made a few adjustments to your CSS:

#responsive-navbar .navbar-nav{
  position: absolute !important;
  right: 0;
}

to ensure the navbar is positioned to the right.

.cover {
  min-height: 500px;
  background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)),url(img/moco-trucks.png);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  color: #fff;
  position: relative;
}

.navbar-dark .navbar-nav .nav-link {
    color: #fff;
}

.navbar-dark:hover, .navbar-dark:focus, .navbar-dark:active{
  color: rgba(199, 84, 40, 1)
}

.nav-item, .nav-link {
  color: #fff;
  text-transform: uppercase;
}

.nav-pills .nav-link.active, .nav-pills .show>.nav-link {
    color: #fff;
    background-color: #c75428;
}

.nav-pills .nav-link.active:hover, .nav-pills .show>.nav-link {
    color: #fff;
    background-color: #a64723;
}

.nav-link:hover, .nav-link:focus, .nav-link:active {
  color: #c75428;
}
#responsive-navbar .navbar-nav{
  position: absolute !important;
  right: 0;
}
<!-- container with bg img -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <div class="cover">
    <div class="container justify-content-end">
      <!-- NAV Here -->
      <nav class="navbar navbar-expand-sm navbar-dark" aria-label="dynamic navbar">
        <a class="navbar-brand" href="index.html"><img src="img/logo.png" width="75%" height="75%"></a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#responsive-navbar" aria-controls="responsive-navbar" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="responsive-navbar">
          <ul class="navbar-nav me-auto mb-2 mb-sm-0">
            <li class="nav-item">
              <a class="nav-link" href="services.html">Services</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="about.html">About</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="contact.html">Contact</a>
            </li>
            <li class="nav-item">
              <a href="get-quote.html"><button class="btn btn-primary" type="submit">Get Quote</button></a>
            </li>
          </ul>
        </div>
      </nav>
    </div>
    <!-- Nav end -->
    <!-- Main Content-->
    <div class="container-xl pt-5">
      <div class="row text-center">
        <div class="col-12">
          <h1 class="py-5">Welcome to Our Website!</h1>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        </div>
      </div>
    </div>
    <!-- End Main Content -->
  </div>
  <!-- End Cover -->

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

`Angular Image Upload: A Comprehensive Guide`

I'm currently facing a challenge while attempting to upload an image using Angular to a Google storage bucket. Interestingly, everything works perfectly with Postman, but I've hit a roadblock with Angular Typescript. Does anyone have any suggesti ...

Tips for implementing sorting and filtering with Ajax and Json in PHP and MySQL applications

Greetings! I'm a newcomer in the world of software development, currently working on a software site. I've successfully built the pages and layout using HTML, CSS, and JavaScript, which was the easy part. Now, my challenge lies in creating main c ...

Attempting to transmit multiple variables

Can anyone provide assistance with passing multiple variables from one page to another? I am able to pass a single variable, but I need to send more than one by clicking a link. Below is a snippet of my code containing the rows I want to transmit to the ne ...

Ways to eliminate the ul elements from the result of a radiobuttonlist

As part of my project, I developed a unique custom field type known as RadioList. This RadioList class is an extension of the RadioButtonList class and utilizes repeatlayout UnorderedList. My goal is to eliminate the <ul> and <li> tags from th ...

Divide the Javascript code from the HTML Canvas

I have been diving into HTML5 Canvas and exploring how to implement it using Javascript code. However, I am facing difficulties separating the Javascript code from the original html file. Despite trying some solutions: HTML5 Canvas not working in extern ...

What is the best way to place an icon in the center of a Bootstrap 5 card image?

I'm looking to center an icon within a bootstrap-5 card image. I have an icon that I want to display at the center of my card image, but I'm unsure how to achieve this using either CSS or Bootstrap-5. Can anyone provide guidance on how to accompl ...

Creating a horizontal line with text centered using Angular Material's approach

Implementing Angular Material, my objective is to design a horizontal line with a word positioned in the center. Similar to the one showcased here. I experimented with this code, achieving a close result, but I aim to align the lines vertically to the mid ...

The slideUp and slideDown functions are not functioning properly

Whenever a user clicks on image-exp, I want description-exp to slide down while other description-exp slides up. I am currently using a Bootstrap template available at this link. To demonstrate the issue, I created a JSFiddle that can be accessed here. H ...

Setting a page title using PHP based on a conditional statement can be achieved by

I am attempting to display a different title for each page In the header.php file, I am checking the file name to set the correct title like this <?php $page = basename($_SERVER['PHP_SELF']); if ($page == 'index.php'): ?> <ti ...

Invoke the parent method within the child application

I have a checkbox on the child app controller. When the user clicks it, I need to call a method from the parent controller: Parent app controller: <div ng-controller="ParentCntr as parentCntr"> <child-app></child-app> </div> C ...

rendering json data as html using javascript

I am encountering some difficulties with displaying JSON data in HTML using JavaScript. Here is the sample JSON data: { "80": { "Id": "80", "FirstName": "Ranjan", "MiddleName": "Kumar", "LastName": "Gupta", "Gender": "Male", "Locat ...

Display users exclusively from the identical company

Is it possible to show only the users from a specific company when a user with Type=Chef logs into the website on the Dashboard? I am not sure how to go about processing this and displaying only the users from their company indicated by Foreign key (fk_Fir ...

deployJava.js injects a new <embed> element into the header section of the webpage

I've ran into an issue with the Java applets on my website. I included the deployJava.js load tag in the head section of the page, but when I look at the resulting HTML in Chrome debugger, this script seems to be breaking my head content and starting ...

Is it possible for Tinymce to provide me with precise HTML content that retains all styles (essentially giving me a true WYSIWYG

I find it puzzling how Tinymce is labeled as a WYSIWYG editor when what I see visually is not exactly what I get when I retrieve the HTML using getContent(). It seems more like "what you see is just what you see." Currently, when I use getContent() to get ...

What could be the reason for my button not activating the form while inside a bootstrap modal?

I have developed a Bootstrap modal with two buttons. Both buttons are submit type and are supposed to trigger the form wrapped around them. However, this is not happening, and I am unable to identify the issue. Here is my code: <?php if ($_SERVER[" ...

Create objects in the gallery

I recently developed a React Material-UI component using Typescript: <Grid container direction="row" justifyContent="flex-start" alignItems="flex-start"> <Grid item xs={5}> <B ...

Combining the Power of Bootstrap with Yii Framework

As a newcomer to the Yii framework, I am looking to incorporate my Bootstrap design into this platform. One issue I have encountered is related to my custom CSS. In Bootstrap, we use navbar-default for styling the navbar. I customized my navbar color by ...

Combining various data entries within a unified form

I have a requirement to create a user-friendly page for entering multiple sets of personal information. Users should be able to fill out details for each record separately and then submit all the records at once. My goal is to design the page in such a wa ...

Changing the text color of the Vuetify Table header is a simple way to customize the

I am currently working on a Vuetify table with the class condition-table. I have applied the following CSS styling: .condition-table { background-color: #e1f5fe70; } The styling seems to work fine so far. However, when I added this additional CSS: .co ...

Tips for securing my div in place when interacting with an expanding panel

I am attempting to create a visualization similar to this: https://i.sstatic.net/Wxdqr.png Instead of using the built-in card and card-column classes in Bootstrap, I noticed that when I expand a panel, all my <div>s start moving around haphazardly: ...