Center the navbar menus at the bottom

Trying to position two menus on a webpage can be challenging. One needs to show at the center bottom, while the other should appear in the top right corner. When attempting to achieve this layout, it's important to ensure that both menus are displayed correctly.

The ideal layout for this setup would look something like this:

**********************************************************************************
                                                            Home About User Login
Logo Heading         
                  Link1  Link2  Link3  Link4  Link5
**********************************************************************************

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"/>
<style>
   .navbar-nav {
      flex-direction: row;
    }

    .nav-link {
      padding-right: .5rem !important;
      padding-left: .5rem !important;
    }

    /* Fixes dropdown menus placed on the right side */
    .ml-auto .dropdown-menu {
      left: auto !important;
      right: 0px;
    }
   .navbar-nav > li > a 
    {
       padding: 0;
       margin: 0;
      vertical-align: bottom;
    }
  </style>

<nav class="navbar navbar-expand-lg navbar-dark bg-primary rounded">
             <a class="navbar-brand" href="">
                <img style="width: 64px;height: 64px;" src="../../Images/new.png" >Heading
            </a>
  <ul class="navbar-nav mr-auto">
    <li class="nav-item active" ID="link1" runat="server" >
      <a class="nav-link">Link1</a>
    </li>
    <li class="nav-item active" ID="link2" runat="server" >
      <a class="nav-link">Link2</a>
    </li>
    <li class="nav-item active" ID="link3" runat="server" >
      <a class="nav-link">Link3</a>
    </li>
    <li class="nav-item active" ID="link4" runat="server" >
      <a class="nav-link">Link4</a>
    </li>
    <li class="nav-item active" ID="link5" runat="server" >
      <a class="nav-link">Link5</a>
    </li>

  </ul>
  <ul class="navbar-nav ml-auto">
    <li class="nav-item">
      <a class="nav-link" href="../../page.aspx">Home</a>
    </li>
          <li class="nav-item">
      <a class="nav-link" href="../About.aspx" >About</a>
    </li>
                <li class="nav-item">
      <a class="nav-link" href="../User.aspx">User</a>
    </li>
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><asp:Label ID="LogOnUser" runat="server"></asp:Label></a>
      <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item" href="#">Log Out</a>
      </div>
    </li>
  </ul>
</nav>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>

Answer №1

You're almost there! Just add an mx-auto and mt-auto for the bottom-center menu, and an mb-auto for the top-right menu to make it work perfectly.

NOTE: This setup may not work well on smaller screens due to treating everything as columns that wrap. You can consider absolute positioning for the top-right menu on smaller screens if needed.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
<style>
  .navbar-nav {
    flex-direction: row;
  }
  
  .nav-link {
    padding-right: .5rem !important;
    padding-left: .5rem !important;
  }

  .ml-auto .dropdown-menu {
    left: auto !important;
    right: 0px;
  }

  .navbar-nav>li>a {
    padding: 0;
    margin: 0;
    vertical-align: bottom;
  }
</style>

<nav class="navbar navbar-expand-lg navbar-dark bg-primary rounded">
  <a class="navbar-brand" href="">
    <img style="width: 64px;height: 64px;" src="../../Images/new.png">Heading
  </a>
  <ul class="navbar-nav mx-auto mt-auto">
    <li class="nav-item active" ID="link1" runat="server">
      <a class="nav-link">Link1</a>
    </li>
    <li class="nav-item active" ID="link2" runat="server">
      <a class="nav-link">Link2</a>
    </li>
    <li class="nav-item active" ID="link3" runat="server">
      <a class="nav-link">Link3</a>
    </li>
    <li class="nav-item active" ID="link4" runat="server">
      <a class="nav-link">Link4</a>
    </li>
    <li class="nav-item active" ID="link5" runat="server">
      <a class="nav-link">Link5</a>
    </li>
  </ul>
  <ul class="navbar-nav ml-auto mb-auto">
    <li class="nav-item">
      <a class="nav-link" href="../../page.aspx">Home</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="../About.aspx">About</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="../User.aspx">User</a>
    </li>
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <asp:Label ID="LogOnUser" runat="server"></asp:Label>
      </a>
      <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item" href="#">Log Out</a>
      </div>
    </li>
  </ul>
</nav>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>

Answer №2

Check out this code snippet for some help.

.navbar-nav {
flex-direction: row;
}

.nav-link {
padding-right: .5rem !important;
padding-left: .5rem !important;
}

/* Adjust dropdown menus placed on the right side */
.ml-auto .dropdown-menu {
left: auto !important;
right: 0px;
}
.navbar-nav > li > a 
{
padding: 0;
margin: 0;
vertical-align: bottom;
}
.bottom_menu{
margin-top: 30px;
}
.top_menu{
margin-bottom: 30px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
<nav class="navbar navbar-expand-lg navbar-dark bg-primary rounded justify-content-md-center">
   <a class="navbar-brand" href="">
    <img style="width: 64px;height: 64px;" src="../../Images/new.png" >Heading
  </a>
   <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse justify-content-between align-items-center w-100" id="navbarNavDropdown">
  <ul class="bottom_menu navbar-nav ml-auto text-md-center">
    <li class="nav-item active" ID="link1" runat="server" >
      <a class="nav-link">Link1</a>
    </li>
    <li class="nav-item active" ID="link2" runat="server" >
      <a class="nav-link">Link2</a>
    </li>
    <li class="nav-item active" ID="link3" runat="server" >
      <a class="nav-link">Link3</a>
    </li>
    <li class="nav-item active" ID="link4" runat="server" >
      <a class="nav-link">Link4</a>
    </li>
    <li class="nav-item active" ID="link5" runat="server" >
      <a class="nav-link">Link5</a>
    </li>

  </ul>
  <ul class="top_menu navbar-nav ml-auto justify-content-md-center justify-content-start flex-nowrap">
    <li class="nav-item">
      <a class="nav-link" href="../../page.aspx">Home</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="../About.aspx" >About</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="../User.aspx">User</a>
    </li>
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><asp:Label ID="LogOnUser" runat="server"></asp:Label></a>
      <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item" href="#">Log Out</a>
      </div>
    </li>
  </ul>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

Answer №3

Is this what you are looking for?

<style>
  #header{
  position: relative;
  width: 100%;
  height: 100px;
  background-color: orange;
}

a{
  display: inline-block;
  width: 50px;
}

#logo, #navigation, #url{
  position: absolute;
}

#logo{
  top: calc(50%);
}

#navigation{
  top: 0;
  right: 0;
}

#url{
  left: calc(50% - 125px);
  bottom: 0;
}
</style>

<div id = "header">
  <div id = "logo">
    LOGO
  </div>

  <div id = "navigation">
        <a>Home</a>
        <a>About</a>
        <a>User</a>
  </div>

  <div id = "url">
    <a>Link1</a>
    <a>Link2</a>
    <a>Link3</a>
    <a>Link4</a>
    <a>Link5</a>
  </div>
</div>

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

Reduce the size of your CSS files using Gulp through the .pipe method

Is it feasible to incorporate a plugin like clean-css to minify CSS every time a page is refreshed or saved? How can I chain it through pipes to ensure that the minified file ends up in the dist folder? Thank you for any assistance! Presented below is the ...

Media queries in CSS not functioning as intended

Trying to scale media requests with an image (logo) for various mobile devices like iPhone 5, 6, 6+, iPads, and large screens. Need to specify styles for portrait and landscape orientation as well. The code seems to be functioning only for iPhone 6, iPads ...

The fluid table within the Bootstrap container is not adapting to different screen

Can't figure out why the bootstrap container fluid table is not responsive. Even though I used an example of My First Bootstrap Page that works fine and is responsive, this particular table remains unresponsive. I want to avoid using a scroll but will ...

Having issues with Tailwind classes not being applied properly on dynamically generated pages in Gatsby-node

Currently, I am working on building dynamic pages using gatsby-node. The templates for these pages are stored in the templates/ directory. However, I have run into an issue where I cannot utilize tailwind classes within these templates unless they are al ...

Steps to turn off a Material UI CSS class for an element universally

Utilizing the Material UI Typography element with the css class MuiTypography-h1, I am seeking to globally disable its usage throughout the entire codebase. <Typography variant="h1" sx={{ width: '100px', height: '55px ...

Is it possible to generate distance between 2 elements without utilizing padding or margin?

In my React Native project, I'm currently working with 2 inline buttons - the search and add buttons: https://i.stack.imgur.com/tKZrf.png I'm looking to add some spacing between these buttons without impacting their alignment with the left and ...

Steps to display a variable in JavaScript on an HTML textarea

I'm working on a JavaScript variable called 'signature' var signature; //(Data is here) document.write(signature) Within my HTML document, I have the following: <div id="siggen"> <textarea id="content" cols="80" rows="10">& ...

Aligning image vertically

I'm working on aligning an image vertically in my header. Currently, it's horizontally centered. header { background-color: blue; height: 118px; width: 1024px; text-align: center; } .container { margin-left: auto; margin-right: aut ...

Harnessing the power of the Zurb Foundation 4 grid system to create visually appealing list elements

When it comes to styling the layout of a page, Foundation 4's grid system with its mobile-first approach is a no-brainer, especially if you're already using other foundation elements like textual content, images, and sidebars. On the example pag ...

Adding or Deleting Rows from Input Table

I'm in the process of creating a website that features an input table allowing users to easily add or remove rows at their discretion. The desired UI is shown below: https://i.sstatic.net/EFAlM.jpg Here is the HTML code I have developed so far: & ...

Hover over to reveal the button after a delay

I'm struggling with implementing a feature in my Angular code that displays a delete button when hovering over a time segment for 2 seconds. Despite trying different approaches, I can't seem to make it work. .delete-button { display: none; ...

Utilizing the NG-CLASS directive within a material table to target a specific 'row' element for styling in CSS

I have a table with various columns, one of which is a status field. I am looking to display colored badges in that column based on the status of each record, which can be "Completed", "Deleted", or "Canceled". I have attempted to use ng-class to dynamical ...

What is the best way to adjust the size of an image within a div element using HTML?

I've created a Carousel with 5 images to display. However, I'm having an issue where only the image is showing up, and I want the text and button to appear below it. Here's how the nature image is currently displaying: What I want is for th ...

How come using float:right causes the div to float towards the left instead?

I am new to CSS and currently facing a problem with positioning a div (#inner) in the bottom-right corner of another div (#container). Initially, I used float: right;, but upon inspecting the Html, I noticed that the inner div is appearing in the bottom-le ...

Ways to verify if the CSS background-color is set to white?

I am looking for a solution: $('*').click(function() { if($(this).css("background-color") == "#ffffff") { $(this).css("background-color") == "#000000" } });​​​​ that will execute on click of a specific cla ...

Issue with Firefox: Click event not triggered when clicking on CSS pseudo element

Check out my custom-made button: <button class="btn-close">Close alert</button> Here's the CSS styling for the button: .btn-close{ position: relative; height: 30px; border: none; background-color: #332b2a; color: #ff ...

Guidelines for positioning an object to float in the bottom right of a separate tag

I am trying to position an image at the bottom right of a parent div. The CSS solution I found from another answer did not work as expected, so I had to use JavaScript to achieve the desired result. Is there a way to do this without using JavaScript? (Pl ...

Using jQuery to apply a CSS border to an image within a textarea

Working with TinyIMCE, I am looking to incorporate a border around all images within the textarea whenever a user submits the form. $("form").submit(function() { var content = $("#edit-message1-value").val(); // Afterwards, I want to manipulate the cont ...

Tips for adjusting the height of both an iframe and a div to fit perfectly at 100% combined

Struggling to make an iframe and div both have 100% full height on the page? I need a footer menu with 280px height, leaving the rest of the page for the iframe. After extensive research, it seems like jQuery might be necessary as CSS Flex didn't wor ...

unable to connect css file to document

My index.html file is not reading the style.css file for some reason, even though it is linked. I have added the type and checked the path, but still facing issues. Can anyone help troubleshoot this problem? Thank you. https://i.sstatic.net/xxpBV.png htt ...