How can I ensure that my navbar-right remains fixed to the right side of the screen and is always visible at the top of the page as I

When the page first loads:

After scrolling down:

I am attempting to create a fixed navigation bar at the top of the screen, so that it remains visible as the user scrolls down the page. However, I am facing an issue where my navbar brand is positioned to the left and the links to other sections are supposed to be on the right. When I apply position: fixed to the navbar brand, it works correctly, but when I try to apply it to any other classes related to the links, they end up getting fixed to the left side and overlapping with the brand or appearing directly below it. I cannot seem to figure out why this is happening.

I have experimented with applying position: fixed to various classes within the navbar without success. I also tried using float: right!important to force the items to the right. Most of the resources I found suggest adding position: fixed to the .nav class, but doing so causes the items to shift to the left. I have included the HTML for my nav, as well as the CSS for the nav, background-video, and modal linked in the nav, in case there is a specific reason causing this problem. Any assistance would be greatly appreciated!

HTML

<nav class="navbar">
      <div class="container-fluid">
        <div class="navbar-header">
          <a href="#home"><h3>allicndev</h3></a>
        </div><!-- /navbar-header -->
        <ul class="nav navbar-nav navbar-right">
          <li class="active"><a href="#about" class="db-line">About</a></li>
          <li class="active"><a href="#portfolio">Portfolio</a></li>
          <li class="active">
            <a href="#" data-toggle="modal" data-target="#myModal">Resume</a>
          </li>
          <li class="active"><a href="#skills">Skills</a></li>
          <li class="active"><a href="#contact">Contact</a></li>
        </ul><!-- /nav navbar-nav navbar-right -->
      </div><!-- /container-fluid -->
    </nav>
    <!-- /navigation -->
    <!-- modal -->
    <div class="modal fade" id="myModal" role="dialog">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">X</button>
        <h4 id="myModalLabel" class="modal-title">Resume</h4>
      </div><!-- /modal-header -->
      <div class="modal-content">
        <embed id="modal-embed" src="assets/anresume.pdf">
      </div><!-- /modal-content -->
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div><!-- /modal-footer -->
    </div><!-- /modal fade -->
    <!-- /modal -->

CSS

* {
  box-sizing: border-box;
}
html, body {
  width: 100%;
  height: 100%;
  margin: 0px;
  padding: 0px;
  overflow-x: hidden;
  position: relative;
}
body {
  margin: 0;
  font-family: 'Montserrat', Arial, sans-serif;
  font-size: 17px;
}
#myVideo {
  position: absolute;
  right: 0;
  bottom: 0;
  min-width: 100%;
  min-height: 100%;
}
.container-fluid {
  padding-right: 30px;
  /* position: fixed; */
}
nav {
  height: 75px;
  display: border-box;
  color: white;
  font-size: 12px;
  text-align: center;
  position: fixed;
  /*z-index: 10px;*/
}
nav.navbar {
  width: 100%;
}
.navbar-header {
  position: fixed;
}
.nav.navbar-nav.navbar-right > li {
  padding-top: 15px;
  margin: 10px;
}
.nav > li > a {
  display: inline;
  padding-left: 0;
  padding-right: 0;
  padding-top: 5px;
  background-color: transparent;
}
.navbar-nav>.active>a, .navbar-nav>.active>a:focus, .navbar-nav>.active>a:hover {
  background-color: transparent;
}
a.db-line {
  transition: white .3s linear;
}
a {
  color: white;
  text-decoration: none;
}
a > h3 {
  color: white;
  text-decoration: none;
}
a:hover {
  color: #f97f04;
}
/* a:visited {
  color: #EDCF10;
} */
.modal {
  display: none;
  height: 100%;
  left: 10px;
  position: fixed;
  top: 0;
  width: 100%;
}
.modal.open {
  display: block;
}
.modal-header,
.modal-footer {
  height: 75px;
}
.modal-content,
.modal-footer {
  width: 100%;
}
.modal-footer {
  bottom: 0px;
}
#modal-embed {
  width: 100%;
  height: 75vh;
}

My desired outcome is for the "allicndev" brand to be on the top left and the links ("about", "portfolio", "resume", "skills", and "contact") to be on the top right, while keeping the entire navigation bar visible even as the page is scrolled through or different sections are targeted.

Answer №1

Definitely utilize the fixed-top class for a navbar that should remain fixed at the top while scrolling

<div class="navbar fixed-top">

</div>

Answer №2

The code provided is using Bootstrap 3 markup, which may cause issues since this question is tagged under Bootstrap 4.

If we assume Bootstrap 4 should be used, ensuring the correct markup and classes are added can help achieve the desired outcome. Here is an example: https://jsfiddle.net/4rtjcpzm/1/

<!-- 
  Bootstrap docs: https://getbootstrap.com/docs
-->

<nav class="navbar navbar-expand fixed-top">
  <div class="container-fluid">
    <a class="navbar-brand" href="#home">allicndev</a>
    <div class="collapse navbar-collapse in" id="navbarCollapse">
    <ul class="nav navbar-nav ml-auto">
      <li class="nav-item active"><a href="#about" class="nav-link db-line">About</a></li>
      <li class="nav-item "><a href="#portfolio" class="nav-link">Portfolio</a></li>
      <li class="nav-item ">
        <a href="#" class="nav-link" data-toggle="modal" data-target="#myModal">Resume</a>
      </li>
      <li class="nav-item "><a class="nav-link" href="#skills">Skills</a></li>
      <li class="nav-item "><a class="nav-link" href="#contact">Contact</a></li>
    </ul><!-- /nav navbar-nav navbar-right -->
    </div>
  </div><!-- /container-fluid -->
</nav>

The ml-auto class (which stands for margin-left: auto) is responsible for positioning the links to the right side. Both fixed-top and sticky-top classes will keep the navbar at the top of the viewport.

Using the sticky-top class might be better as it avoids the need to adjust body content down (padding-top in the CSS part of the fiddle); however, this depends on browser support for position: sticky;.

Additionally, note that nesting a heading element like <h3> inside an anchor element <a> is not valid HTML by default, as <h3> is a block element and <a> is an inline element according to the HTML spec.

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

The scrollbar remains unresponsive and fixed until the screen size is adjusted

Need some assistance with a website project for a client. The scrollbars on each page are not loading or changing height until the window is resized. I have a jQuery scrollbar in place, but disabling it does not solve the issue as the normal scrollbar beha ...

How to use JQuery to parse an external JSON file with array elements in Javascript

My goal is to extract information from an external JSON file using JavaScript, specifically an array and other elements. The JSON file I am working with is called 'TotalUsers.json' {"@version":"1.0", "@generatedDate":"12/20/10 5:24 PM", "day":[{ ...

What causes the difference in output between passing p=3+3 using GET, which results in 3 3, and using POST, which results in

It's really quite puzzling - I've noticed that sending the same parameter through various methods yields different results. ...

How to create a responsive image that appears over a button when hovering in Bootstrap?

My goal is to display an image over a button when hovering. I've tried adding the .img-responsive class in Bootstrap while including the image in the HTML, but it's not working as expected with my current method of loading images. The buttons the ...

How can one effectively style text to appear italic using CSS and HTML?

What is the proper method to italicize text? I have come across these four different approaches: <i>Italic Text</i> <em>Italic Text</em> <span class="italic">Italic Text</span> <span class="footnote">Italic Tex ...

Struggling to get the max-width property to function properly with a Bootstrap multi-level dropdown menu

I have a multi-level Bootstrap dropdown menu that I am customizing based on the design featured in this bootsnipp. However, I am encountering an issue where some of my menu items are too lengthy, so I need to restrict their width to a maximum of 400px. Ad ...

Tips for maintaining a scrollable Material-UI Table with dynamic height?

I'm encountering an issue with the Material-UI Table component in terms of its size and scrollability. Summary: The Material-UI table only becomes scrollable when its parent has a fixed size. If I set the size to 100% to fit the parent, it overflows. ...

What is the best way to adjust the dimensions of a blank image without altering the size of

I am attempting to set the size of an empty image to 150px. While using float: left works on Firefox, it does not have the same effect on Google Chrome. Here is the HTML code: <div> <img src='some broken url' alt='no image'& ...

Tips for maintaining consistent width of a div:

My current project involves designing a website that displays various quotes, with each quote rotating for a specific amount of time. However, I'm facing an issue where upon loading the page, the first quote triggers the appearance of a scrollbar, mak ...

Experiencing difficulties with setting the width of owl carousel

Here is the HTML code snippet: <div class="row"> <div class="col-lg-7 col-sm-6"> <div class="owl-carousel" id="homeCarousel"> <div class="item"> <img src="images/brela.jpg" alt="brela makarska"> </d ...

A step-by-step guide on revealing a complete div upon selection

Can anyone assist me in showing a div with a form inside it whenever a specific option is selected from a tag? Here is the code I currently have: <script type="text/javascript"> $(function() { $('#contactOptionSelect&apo ...

Is there a way to ensure that the Bootstrap toggle starts off in a collapsed state?

I need assistance with creating a toggle feature where clicking on a line of text will reveal more text below, and when clicked again, the extra text collapses. I want the text color to change to blue when collapsed and red when expanded. The only issue is ...

Embedding a YouTube video in a view player using HTML5

So I've got a question: can you actually open a youtube video using an HTML5 video player? I'm looking for a more mobile-friendly way to watch youtube videos, and my idea was to upload a thumbnail image and then set up an onclick function to disp ...

Tips on utilizing toggleClass to display only the currently active item and obtaining the active class name

I am new to Jquery and CSS/scss and I have successfully created a dynamic boostrap card that resembles a record player. The goal is to generate multiple boostrap cards based on the data in DB, but for simplicity, I am showing only 2 examples below. My ques ...

What do I do when I encounter the error message "Provider not found for RadioControlRegistry" in Angular 2? Which provider should

Which provider should be included in the provider component? <div class="radio"> <input let match id="male" type="radio" name="gender" value="true" [(ngModel)]="isMatching" (click)="isMatching(match.value)" > Take a look at my console output ...

Enigmatic void found beneath image surfacing

Similar Question: Dealing with Additional Space at the Bottom of an Anchor Tag Take a look at this example page here.. There seems to be a mysterious gap below the picture of the family, just before the gray-bordered (5px #333) div that holds the ima ...

Addressing Layout Problems When I Enlarge the Browser Width

My website is www.adventureswithross.com When the device width is larger than 601px, I have specific requirements: I need the menu and custom header to be seamlessly connected without any spacing in between. To address the issue of space above the custo ...

Creating a circular image with a vibrant color light effect that seamlessly runs across all browsers: What you need to know

Recently, I was working on a project involving this website that utilizes the Bootstrap framework. One interesting feature of the website is circle-shaped images that create a color light effect when hovered over. To achieve this, I decided to use the CSS ...

designing icon buttons

I am interested in adding big buttons with icons to my website. I have images named largebut_hover.png, largebut.png, and icon.png. The icon image is supposed to be displayed inside the light grey background of largebut.png, and when hovering, it should sw ...

How to achieve horizontal auto-scrolling in an image gallery with jQuery?

Hey there, I'm currently working on an Image Gallery project. I have arranged thumbnails horizontally in a div below the main images. Take a look at this snapshot img. My goal is to have the thumbnails scroll along with the main pictures as the user ...