Shifting the Location of an li Element within a Div

I have a navigation bar positioned at the top of my webpage. On the right side of this navigation bar, I have a list of navigation items which are represented as list items within an unordered list (ul) inside of a div element. https://i.sstatic.net/T0NYS.png

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>David Chu's China Bistro</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link href='https://fonts.googleapis.com/css?family=Oxygen:400,300,700' rel='stylesheet' type='text/css'>
    <link href="https://fonts.googleapis.com/css2?family=Lora&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">
    <link rel="stylesheet" href="css/styles.css">
  </head>

<body>
  <header>
   <nav id="header-nav" class="navbar navbar-expand-md"> 
    <div id="navbarNav" class="collapse navbar-collapse">
       <ul id="nav-list" class="nav navbar-nav navbar-right">
        <li>
          <a href="menu-categories.html">
            <span class="material-icons">
            restaurant_menu
            </span><br class="d-none d-md-block"> Menu</a>
        </li>
        <li>
          <a href="#">
            <span class="material-icons">
              info
            </span><br class="d-none d-md-block"> About</a>
        </li>
        <li>
          <a href="#">
            <span class="material-icons">
              emoji_events
            </span><br class="d-none d-md-block"> Awards</a>
        </li>
        <li id="phone" class="d-none d-md-block">
          <a href="tel:410-602-5008">
            <span>410-602-5008</span></a><div>* We Deliver</div>
        </li>
      </ul>
     </div>
    </nav>
  </header>

</body>
</html>

The issue I am facing is that the div containing the navigation list has excessive space on the right side, resulting in the phone number moving up when the screen width expands. My goal is to have the list item aligned to the right so that its position remains consistent regardless of screen expansion.

https://i.sstatic.net/J020Q.png

Although I am utilizing Bootstrap 4 and have researched extensively about using flex properties, none of the solutions seem to be effective. Additionally, I am attempting to create a responsive navigation menu that collapses based on screen size, hence why I am utilizing these specific classes.

I aim to maintain the layout of the items exactly as shown in image 1 under any circumstance, with the telephone number appearing below the other items.

       body {
  font-size: 16px;
  color: #fff;
  background-color: #61122f;
  font-family: 'Oxygen', sans-serif;
}

/** HEADER **/
#header-nav {
  background-color: #f6b319;
  /*position: relative;*/
}

#logo-img{
    background: url('../images/restaurant-logo_large.png') no-repeat; 
    width: 150px;
    height: 150px;
    margin: 10px 15px 10px 0;
}

a.navbar-brand {
  padding-top: 25px;
  font-family: 'Lora', serif;
  color: #557c3e;
  font-weight: bold;
  font-size: 1.5em;
  text-transform: uppercase;
  text-shadow: 1px 1px 1px #222;
  line-height: .75;
}

.navbar-brand a:focus, .navbar-brand a:hover{
    text-decoration: none;
}

p.kosher {
    text-transform: uppercase;
    margin-top: 10px;
    color: #000;
    font-size: .7em;
}

p.kosher span{
    vertical-align: middle;
}

#nav-list {
  margin-top: 10px;
}
#nav-list > li {
    margin-right: 15px;
}

#nav-list a {
  color: #951C49;
  text-align: center;
}
#nav-list a span {
  font-size: 1.8em;
}
#phone {
  margin-top: 5px;
}
#phone a { /* Phone number */
  text-align: right;
  padding-bottom: 0;
}
#phone div { /* We Deliver */
  color: #557c3e;
  text-align: right;
  padding-right: 15px;
}

button.navbar-toggler{
  clear: both;
  margin-top: -70px;
  margin-right: 0px;
}
li > a:hover, li > a:focus {
  text-decoration: none;
}
#nav-list {
  margin-top: 10px;
  display:flex;
  flex-wrap:wrap;
  justify-content:space-between;
  max-width: 220px;
}

#nav-list li:last-child {
  width:100%;
  margin-right:0px;
}

Answer №1

To begin, we need to set a max-width for the #navbarNav:

#navbarNav{
  max-width:220px;
}

Next, include the following code for #nav-list:

#nav-list {
    margin-top: 10px;
    display:flex;
    justify-content:space-between;
}

Now, if you want to align the #navbarNav to the right, there are multiple methods to achieve this. One way is by using flexbox. To implement this, add the code below to the parent element of #navbarNav, which is the #header-nav:

#header-nav{
  display:flex;
  justify-content:flex-end;
}

However, keep in mind that this will align all elements within your #header-nav to the right. If nothing else is placed in the #header-nav, you can simply utilize this code.

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

Adjusting the size of background images using media queries to scale down accordingly with the size of the browser window while

Currently, I am working on a website project where I am using a background image with Bootstrap 4. However, I am facing an issue where the image does not center properly as it resizes at different breakpoints. I am contemplating whether to use resized im ...

Unable to load YouTube video player

Having trouble getting the Youtube embed code to work, any suggestions on fixing it? Check out this link for potential solutions ...

Having issues with my Bootstrap navigation dropdown - any suggestions on what I might be overlooking?

I'm having trouble getting the bootstrap dropdown and button to function properly when the menu collapses on tablet or mobile view. Below is my HTML code for the navigation: <nav class="navbar navbar-default navbar-fixed-top"> <div c ...

Sending a div class as a parameter to a JavaScript function

Wondering if it's possible to pass a div's class into a JavaScript function. I'm using SquareSpace so adding an id to the div is not an option, but it works fine with divs that have ids. JQuery is already loaded. This is my current train of ...

Trying to implement a personalized cursor with CSS was unsuccessful

I implemented a custom cursor for my website using an .ico file, but unfortunately it's not displaying correctly. Here's the CSS I used: html, body { cursor: url("images/39020_fPv_icon.ico"), url("images/39020.png"), defa ...

Incorporate an SCSS file into the Stackblitz project

Is there a way to include an scss file in the stackblitz? I attempted it, but encountered some issues. Could you take a look and advise me on what to do? I also made an attempt to add home.html This is the project: Check out the stackblitz project here! ...

Using Javascript's Speech Recognition to activate a button

I am new to using JavaScript Speech Recognition and decided to work with the Annyang library. My goal is to automatically trigger the "show date" button when the user says 'hello', without actually clicking the button. However, I've been fac ...

Execute the function with various parameters

I'm currently working on a form using HTML and JavaScript. One issue I'm facing is changing the focus when clicking on an input text field. I have created a function for this purpose, but I want to make it reusable for all input text fields, inst ...

Troubleshooting Bootstrap 4: The .col class is experiencing issues with functionality

Why is the .col-6 class malfunctioning on screen sizes below 575px, causing the cards to appear distorted? How can this issue be resolved? To see the problem, click on Run code snippet->Full Page and resize the screen width to below 575px: .divCard{ ...

Open a pop-up window without displaying the navigation toolbar

I have been trying to open a new popup window without the navigation toolbar using the following code. However, it is still opening with the navigation toolbar. Can someone assist me in resolving this issue? <script type="text/javascript> function ...

What is the method for assigning a data-group value to an HTML element generated in C#?

In my current situation, I am faced with the task of conditionally sliding up or hiding sets of controls and elements. I came across a helpful answer on Stack Overflow from user QBM5 which suggests assigning data-groups to the controls that need to be slid ...

Sliding right is done by activating the Switch Function, while sliding to the left can be achieved by deactivating it with the help

My objective is to create a functionality where flipping the switch button will cause it to slide automatically to the right, revealing a red background div. When switched off, it should return to its original position with a yellow background using Jquery ...

Unable to position the button next to the search bar

I'm struggling to get my search bar aligned next to my dropdown button. I've tried various alignment methods without success. Both buttons are within a container, causing the search bar to span 100% of the container's width. I also attempted ...

Guide to positioning a div at the bottom of a Drawer while maintaining the same width as the Drawer in React Material UI

Creating a Drawer on the right-hand side using <Drawer/>, I am trying to make a <div> stick to the bottom of the <Drawer />. The width of this <div> should match the width of the <Drawer />. Desired Outcome: https://i.sstati ...

Locating an individual element using Selenide (Selenium) and the cssSelector method

If you have a structure of elements similar to the one shown in the image, it is possible to extract each static property using: $$('#static-information .value').get(0) or $$('.static-property .value').get(0) However, as each static p ...

Material Design Lite - Adding a Search Bar to the Navigation Header

While loading this page from here, you may notice that the right side does not match the left. I am seeking guidance on how to fix this issue. I would like the padding on the right to mirror that of the left side. <div class="mdl-layout__hea ...

Compatibility of Blackberry Webworks

As I prepare to build a Webworks app, the documentation indicates that it is designed to function only on devices equipped with OS 5.0 or later. However, I am curious if there exists a way to make the app compatible with devices running an OS version lower ...

Concealing the rear navigation button within the material carousel

I have a material css carousel, and I am trying to hide the back button on the first slide. I attempted to use the code below from a previous post The following code snippet prevents the user from looping through the carousel indefinitely. Stop looping i ...

Mysterious element materializing within the code featuring the attribute "data-original-title"

I've noticed a mysterious div that keeps popping up in the code of the website I'm currently working on. It seems like countless developers have tinkered with this project over time. This page is utilizing Bootstrap and is based on a .Net forms ...

CSS: Choose elements that have a single parent that matches the attribute selector

I'm relatively new to coding, so please bear with me if this seems like a silly question. I'm currently working on developing a general-purpose scraper to extract product data using the "schema.org/Product" HTML microdata. Unfortunately, I encou ...