Elevate your website design with Bootstrap by placing a fixed horizontal navigation bar above all

I am facing an issue with my vertical Bootstrap sidemenu that transitions to horizontal layout responsively.

When the sidemenu switches to a horizontal display, it ends up being hidden behind other elements, particularly on smaller devices. The example demonstrates how the sidemenu gets obscured by text:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<!DOCTYPE html>
<html lang="en">
  <head></head>

<body style="padding-top:55px">

  <nav class="navbar navbar-expand-sm navbar-light fixed-top bg-light">
    <a class="navbar-brand" href="#">Fixed navbar</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="navbar-collapse collapse justify-content-between align-items-center w-100" id="collapsingNavbar2">
      <ul class="navbar-nav mx-auto text-md-center text-left">
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
      </ul>
    </div>
  </nav>


  <div class="container">
    <div class="row">
      <div class="col-12 col-md-4">
        <div class="position-fixed bg-dark">
          <div class="row">
            <ul class="nav overflow-auto flex-md-column flex-nowrap">
              <li class="nav-item">
                <a class="nav-link" href="#">Link 123</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">Link 123</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">Link 123</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">Link 123</a>
              </li>
            </ul>
          </div>
        </div>

      </div>


      <div class="col-12 col-md-8">
        <div class="row">
          <div class="d-flex">
            <h1>Some text</h1>
          </div>
        </div>

      </div>



    </div>
  </div>


</body>

</html>

https://codepen.io/coffeeeecup/pen/ZEYpBJO

The issue is likely due to the position-fixed property. However, I need this attribute for the sidemenu to remain fixed when scrolling. How can I make sure that elements are positioned below the sidemenu with position-fixed?

Thank you in advance!

Answer №1

To ensure the fixed element is displayed properly, apply a z-index of 1. Also, consider adding padding to the content based on the height of the fixed element.

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

Tips for positioning a label at the top of a table row in an asp.net C# application

I am facing an alignment issue in my asp.net page with a table that contains a label and a textbox. Despite trying various methods, the label consistently displays at the bottom of the row. How can I ensure that the label is aligned to either the center or ...

Problem with Button Functionality in Outlook Email

I am having trouble making a specific button for Outlook within my email. Due to the different sections in my EMAIL, the button got wrapped in v:rect and now it is shifting to the top of the email. Can someone assist me with this issue? Actual Image - htt ...

Angularjs still facing the routing issue with the hashtag symbol '#' in the URL

I have recently made changes to my index.html file and updated $locationProvider in my app.js. After clicking on the button, I noticed that it correctly routes me to localhost:20498/register. However, when manually entering this URL, I still encounter a 4 ...

Creating precise squares in JavaScript and animating their movement at designated intervals

My goal for the Final Project is to create a JavaScript-based game similar to Guitar Hero, but with squares instead of circles representing the notes. In Guitar Hero, players have to hit the notes at specific times. I am facing a challenge in my code wher ...

How can HTML be added in CodeBehind using C# in a WebForm?

I have a method that generates tools based on the number value inserted, and I also have another control called "DateTimePicker" that provides a textbox and date+time picker function. However, the issue arises when I call the dynamic_tools method and inse ...

Prevent jQuery scrollTop from updating the browser history

Is there a way to prevent scrollTop from creating browser history records? Upon launching the page, I want the browser to automatically navigate to a specific section if the URL includes a parameter with an internal anchor name. To achieve this, I use the ...

Exploring asp.net client-side routing using the power of page.js

Currently, I am working on constructing a basic asp.net application using webforms and my goal is to manage routing in the client. Essentially, this will be a Single Page Application (SPA). To handle the routing aspect, I have opted to utilize the page.js ...

Embed the group icon within the upload file button

I've been attempting to create an input group that functions as a file upload button with an icon embedded. Despite my efforts, I haven't been successful with the following code: <div class="row"> <div class="col-xs-10 col-md-6"> ...

What could be the reason behind the repeated console messages when utilizing jquery to replace the src attribute of images?

Overview: An HTML page with two images, identified as #me1 and #me2 The images initially display 1.jpg and 2.jpg Clicking #me1 triggers a GET request to "randim.php" using jQuery to fetch a random filename, which is then set as the src= attribute ...

Exporting Datatables to excel does not remove HTML tags as expected

I recently implemented a data tables export button on my data table. Some of the columns in this table contain HTML tags, such as: <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle btn-xs">BUTTON NAME</butto ...

Is there a way to identify a null dynamic source in Html5 audio?

The HTML5 audio element in my code does not point directly to an mp3 file, but rather to an action in a controller. This action returns either an mp3 file (FileResult) or null, which can take up to 1 minute to retrieve. To handle this delay, I have impleme ...

Retrieve the bounding rectangle of a div that has the CSS style `display: contents` using the getBoundingClientRect

My objective is to apply styling and obtain the bounding box of an entire "row" within a CSS grid, including features like highlighting when hovering over it. To achieve the styling aspect, I make use of the display: contents property, so that the styles ...

Issues with validating and executing Javascript (HTML5 canvas)

Currently, I am tasked with creating a 3D application using HTML5 canvas for one of my courses. To achieve this, I decided to utilize Three.js. My initial goal is to render a simple plane and allow the camera to move along the x-axis when the mouse button ...

What is preventing the function from successfully compiling text from various files that are uploaded using the HTML5 file reader into an array?

My current challenge involves attempting to upload two text files using the HTML 5 file reader. While I can successfully get the files into an array, encountering difficulty arises when trying to return that array from the function. One solution could be ...

Increase the padding and add a border to separate the list items in bootstrap 4

I have a header with some links and I want to create space and add a border between them. I attempted using ::before pseudo-content, but it's not displaying the content where I intended. .header_links_ul { list-style: none; margin: 0; paddin ...

Names picked at random and presented in the innerHTML

I am currently working on a project that involves displaying random names from an array in a text area named "textbox". Currently, I am using math.random() to pick a name randomly, but it only generates a new random name when the page is reloaded. How ca ...

What is the best way to move between different pieces of content using AJAX?

To clarify my current situation, I am using jQuery and AJAX within the main index.php file to load content without refreshing the page. Here is a simplified example of my main index.php page: <!doctype html> <div id="vis"> <?php inclu ...

What is the proper way to write the code for this form?

I am exploring alternatives to using the html TABLE tag and struggling to create the desired layout. I have attached a screenshot showing my table design. How can I achieve the same layout using divs or spans while still maintaining vertical alignment of t ...

Modifying Bootstrap Alert Styles with Jquery

I have an alert in my HTML form as shown below: <div class="alert bg-danger text-white alert-dismissible" id="alert" > <button type="button" class="close" data-dismiss="alert"><span>& ...

Is there a way to include a text file in HTML for referencing or posting on my website?

Managing a website where my colleagues frequently post updates can be time-consuming as I am the only one knowledgeable in html and css. I find myself constantly formatting their posts and creating new pages for them. I am exploring ways to simplify this ...