Repositioning specific elements to the right side of the navigation bar

Greetings, everyone. I am new to CSS and HTML, embarking on my very first project.

Currently, my focus is on creating a navigation menu where I aim to move two items ("SIGN IN" and "CART") to the right side, separate from the rest of the navbar elements. However, despite multiple attempts, I am unable to achieve this desired positioning. The class 'navbar-right' did not yield the desired outcome. Additionally, enclosing the items within a container with relative positioning disrupted the responsiveness of the navbar upon screen size reduction. Moreover, there seems to be an issue with displaying the shopping cart glyphicon.

The code snippet from my main.css file is as follows -

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<head>
    <title>Ecommerce</title>
    {% load static %}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="54363b3b20272026352414617a667a65">[email protected]</a>/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT"
      crossorigin="anonymous">
    <link rel="stylesheet"
          href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
   <link rel="stylesheet" type="text/css" href="{% static 'store/styles.css' %}" />
</head>

<body>
...

In my styles.css, the relevant sections include -

#input{
    width: 500px;
    border: 1px solid #555;
    display: block;
    padding: 9px 4px 9px 40px;
    background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' class='bi bi-search' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'%3E%3C/path%3E%3C/svg%3E") no-repeat 13px center;

}


#formAndButton{
    margin-left: 100px;

}

/* For attempting relative positioning which affected responsiveness */

#moveRight{
    position:relative; left:200px;
}

li { margin-left: 15px }
...

Answer №1

<ul class="navbar-nav ms-auto">
must not be placed inside
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
. They should be adjacent to each other.

<div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
            <a class="nav-link active" aria-current="page" href="#"><i class="fa fa-fw fa-home"></i>Home</a>
        </li>
        <div id="formAndButton">
            <form id="search" method="get" class="d-flex" action="#">
                <input id="input" class="form-control me-2" type="text" placeholder="Search products" aria-label="Search">
                <button class="btn btn-warning text-light" type="submit">SEARCH</button>
            </form>
        </div>
    </ul>
    <ul class="navbar-nav ms-auto">
        <li class="nav-item">
            <a href="#" class="btn btn-warning">SIGN IN</a>
        </li>
        <li class="nav-item">
            <a href="#" class="btn btn-warning"><i class="fa fa-fw fa-shopping-cart"></i>CART</a>
        </li>
    </ul>
</div>

Utilize the font-awesome shopping cart icon for the icon:

<i class="fa fa-fw fa-shopping-cart"></i>
.

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

Can the meta viewport be eliminated using a script?

I currently do not have access to the HTML file on the server side, but I can make changes by adding additional HTML to the website. My issue is with a non-responsive site listed below, which now requires me to zoom in after it loads due to the new viewpor ...

Showing the bootstrap symbol at the same time as the jqgrid heading words

I'm having trouble displaying a twitter bootstrap icon in the jqgrid caption section. The icon is not showing up despite my efforts. Here's the fiddler link: https://jsfiddle.net/99x50s2s/31/ Here's the code I've tried: jQuery("#sg1") ...

"Utilize Flask and HTML to facilitate the uploading of JPG files

As a novice, I am currently working on building a blog using Flask and HTML. However, I have encountered an issue where my blog can only post titles and content, but I would like to include pictures as well. If anyone knows the easiest way to accomplish ...

Card flip animation using RotateY is experiencing delays in loading

While experimenting with jQuery and CSS3 animations, I encountered a strange issue. When hovering over the card or focusing on the CCV field in my pen, there is a delay in the color transition when the card flips over. It almost seems like it's loadin ...

hiding html elements by using the display property set to none instead of physically removing

I am currently utilizing an if-else statement to display different HTML structures. As a result, the entire HTML is being rendered twice. Is there a way we can utilize 'display: none' instead? I attempted to use it in th ...

angular application developed using HTML, CSS, and JavaScript

With my current Angular project, I am working with 4 components (comp1, comp2, comp3, comp4). I came across a code snippet for a form consisting of HTML, CSS, and JavaScript that I want to integrate into comp1. Can you please confirm if I should place the ...

Deleting list items by clicking a button

I'm working on adding a functional "x" button to each list item (li) so that users can click on it to remove the item. I've successfully added the button, but I'm unsure about what code to use in the onClick event to delete the corresponding ...

Adjusting the color of placeholder text when focused on using JavaScript

Is it possible to change the placeholder text color to white when focused using JavaScript? CSS styling doesn't seem to work consistently across different browsers. Here is the contact form for reference: here. I've experimented with various CSS ...

Discover the ins and outs of working with datetime in Android!

I have an Android app that includes HTML files, one of which is a page for playing sound. Users can manage when the sound plays as follows: Saturday on Sunday off Monday on and so on. I have written my code properly, but whenever I select input ...

Switch between including 'light' or 'dark' styles using Javascript?

I am currently working on a project where I aim to incorporate a dark mode toggle feature. To maintain organization and scalability, I have chosen to implement the SASS (.scss) architecture rather than plain CSS. My plan is to utilize variables within my ...

Embracing the use of paragraph tags within tweets on a webpage

For a project on freecodecamp.com, I created a quote machine where you click a button to get a random quote and then have the option to tweet it using the "Tweet It" button. However, I encountered difficulty in getting the quote to display properly in the ...

Insert the META tag data specific to Facebook Instant Articles directly within the JavaScript code

My website is running on a custom-built CMS provided by a company, and it seems like a modified version of WordPress. They are unwilling to include a basic meta tag in our HTML code. I am looking for guidance on how I can incorporate Facebook's Insta ...

Adapt CSS styling based on the URL address

I've searched everywhere, but I can't seem to find a straightforward solution. I think CSS is the way to go. What I'm trying to achieve is changing the CSS style of links based on the URL they lead to. Imagine we have three menu items: H ...

Leverage multiple services within a single AngularJS controller

Is it possible to use multiple services in the same controller? Currently, I am able to achieve this with different services, but it seems to only perform one service. <!DOCTYPE html> <html> <script src="http://ajax.googleapis.com/ajax/libs ...

Loading of local resources is restricted in the Apache web server

I am encountering an issue with my Apache web server on a Raspberry Pi. I need to display graphs using the MPLD3 libraries, which are loaded from the server's folder. When I run my index.php page, I receive a Not allowed to load local resources error ...

"CSS - Struggling with header alignment in a table display element - need help with positioning

During my HTML layout creation process, I encountered a peculiar positioning issue that proved difficult to resolve. Consider the following HTML structure: <div class="outer-wrap"> <div class="header"> I am a Header </div> <div c ...

Error encountered in Django: Unable to locate reverse for 'register' and issue with the "STATIC" parameter

Greetings fellow Django developers! I encountered an issue where the word "static" is showing up in red as an error along with % and } <body id="bg" style="background-image: url({% static 'users/images/bg.png' %});"> E ...

Steps to add the child theme CSS file to the bottom of the <head> section

I am trying to ensure that my child theme's CSS file is loaded after all other stylesheets in order to prevent it from being overridden. The current issue I am facing is that the builder I am using seems to have a bug with responsive design, causing m ...

Issue with the scope of Bootstrap Accordion

Observing that the event triggers on a single Bootstrap accordion can affect all other accordions on the same page, I am wondering if there is a way to isolate this behavior without altering the markup or using $(this). Any suggestions? Check out this exam ...

Bootstrap styles refusing to be overridden

The custom CSS file I imported after the bootstrap CDN is not successfully overriding it. [Inspecting element screenshot can be viewed here.][1] Importing bootstrap and custom css <!-- Bootstrap --> <link rel="stylesheet" ...