Struggling with Bootstrap 4 Navigation - Placement of Icons Challenge

I'm struggling with aligning the search and shopping cart "icons" on mobile. On desktop, the icons should be positioned to the right of the menu as they currently are.

However, I want to move the icons to the left side of the hamburger icon in responsive states. I also want to utilize the CSS utilities that are already provided with BS4 (Bootstrap 4).

Any suggestions? Thank you in advance.

<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Homepage</title>


<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css"> 
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
</head>
<body>

<div class="container text-uppercase">
<nav class="navbar navbar-expand-lg navbar-light">
<a class="navbar-brand my-4" href="#"><img src="https://placehold.it/200x100"></a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link pr-3" href="#">Item</a></li>
<li class="nav-item"><a class="nav-link pr-3" href="#">Item</a></li>
<li class="nav-item"><a class="nav-link pr-3" href="#">Item</a></li>
<li class="nav-item"><a class="nav-link pr-3" href="#">Item</a></li>
<li class="nav-item"><a class="nav-link pr-3" href="#">Item</a></li>
</ul>
</div>
<div class="d-flex justify-content-end">
<i class="fas fa-fw fa-search"></i>
<i class="fas fa-fw fa-shopping-cart"></i>
</div>
</nav>
</div>



<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
</body>
</html>

Answer №1

The navbar in Bootstrap 4 utilizes flexbox, allowing you to utilize the ordering classes for custom adjustments...

<div class="container text-uppercase">
    <nav class="navbar navbar-expand-lg navbar-light">
        <a class="navbar-brand my-4" href="#"><img src="https://placehold.it/200x100"></a>
        <button class="navbar-toggler navbar-toggler-right order-lg-0 order-1" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="d-flex justify-content-end order-lg-2 order-0">
            <i class="fas fa-fw fa-search"></i>
            <i class="fas fa-fw fa-shopping-cart"></i>
        </div>
        <div class="collapse navbar-collapse justify-content-end order-lg-1 order-last" id="navbarNavDropdown">
            <ul class="navbar-nav">
                <li class="nav-item"><a class="nav-link pr-3" href="#">Item</a></li>
                <li class="nav-item"><a class="nav-link pr-3" href="#">Item</a></li>
                <li class="nav-item"><a class="nav-link pr-3" href="#">Item</a></li>
                <li class="nav-item"><a class="nav-link pr-3" href="#">Item</a></li>
                <li class="nav-item"><a class="nav-link pr-3" href="#">Item</a></li>
            </ul>
        </div>
    </nav>
</div>

Related: Customizing section alignment in Bootstrap 4 Navbar when toggled

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

Leveraging the select class in Flask

In my Python application, I am trying to extract the selected value from an HTML/JavaScript form. Below is the snippet of my HTML code: {% block content %} <form method="post"> <div class="form-group"> <label f ...

Issues with HTML Labels disrupting Bootstrap Grid Columns layout

Here is the HTML code I am working with: <div class="row"> <div class="col-xs-12 col-sm-6 col-md-3 col-lg-3"> @*@Html.LabelFor(s => s.BasicInfo.FirstName)*@<label>First Name:</label> </div> <div clas ...

What could be causing my mobile page to require two scrolls?

I've encountered a peculiar issue where users need to scroll twice or the page gets stuck on mobile devices that are less than 600px wide. I've attempted the following solutions with no success. I am a complete novice, so please excuse my lack of ...

What is the best way to place an anchor so that it is perfectly aligned between a static header and footer?

I am looking to create a website where the content is placed below a fixed header and footer. Navigation is to be done through anchors, with only the active anchor being displayed while the rest remains hidden by the header and footer (similar to a window) ...

I can't seem to get my SCSS files to load properly on GitHub HTML pages, and I

Just starting out in the world of programming and decided to showcase my portfolio site on GitHub. While my index page is displaying correctly, I'm encountering issues with some images and all of my SCSS files not showing up. Any assistance or guidanc ...

What sets apart Firefox and Chrome when it comes to interpreting the widths of flex items?

Looking to create a column layout using flexbox with three divs that span the full width of their parent container while maintaining a single line height. If the content in the center div overflows, I want it to display an ellipsis at the end. Check out t ...

An unusual icon with three varying sizes in a single file

I have come across an interesting favicon file. Click here to download the favicon file Unfortunately, I am unable to upload this image file as it does not meet the required format standards. Upon viewing the file in Windows 7, a fascinating discovery w ...

How to use jQuery to convert Latin letters to uppercase in input text

When using the text-transform: Uppercase property, it works fine. However, there is one issue - when I type a lowercase "i", it displays as an uppercase "I" instead of the Latin letter "İ". Is there a way to achieve this using jQuery or another method? ...

Exploring PHP Queries with Div Classes

I'm in desperate need of assistance. I'm currently working on putting together a website and pulling data from a mysql database. The specific div that I'm trying to populate is provided below. The issue I'm facing is how do I integrate ...

The text within the button disappears when in the :before state

After implementing the code from this codepen, I decided to use the 3rd button design. .btn { line-height: 50px; height: 50px; text-align: center; width: 250px; cursor: pointer; } .btn-three { color: #FFF; transitio ...

Using CSS to design a table-like structure with rows that span multiple columns

I am trying to generate a table dynamically using CSS and a JSON array. For example: In the code snippet provided, I have assigned a class of 'spannedrow' to span certain cells in the table, although the class is not defined yet. This is just ...

Can the parent element containing this floated div also have text wrapping around it?

Hello there, I've been following along with this tutorial on CSS Positioning to enhance my understanding: . Everything was going smoothly until I reached step 7 and ran into a roadblock. In that step, the text "id = div-1" is supposed to be positioned ...

Learn the trick to making specific words appear bold in Select2 by changing the font style

I'm currently working with select2 version 4.0.1, and I have a requirement to modify the font for specific words. In particular, I want to display codes AK and HI in a different/bolder font style, similar to the example below: <select id="select2" ...

Activate the drop-down menu in Angular 6 by hovering over it with your mouse

I am just beginning my journey with Angular 6 and Bootstrap. Currently, I am working on a Navigation bar that consists of 3 navigation items. One of the nav items is called "Store", and when a user hovers their mouse over it, I want to display a mega menu ...

Support for TrueType fonts in web browsersLet me know if you

If I have a custom font in TTF format and want to check if @font-face supports it, what script can I use? What are the available options? ...

How come my keyframes animation isn't functioning properly on my div element?

I am currently designing a custom animation for a checkers game. My goal is to create an effect where the checker piece moves slowly to its next spot on the board. Below is the CSS code I have used: @keyframes animateCheckerPiece { 0% {top: ...

Prevent iOS from scrolling both horizontally and vertically

I'm currently in the process of developing a web app and I want to prevent horizontal overflow (elastic band) type scrolling. Despite trying various solutions, such as: html, body {width: 100%; overflow-x: hidden;} Nothing seems to be effective... ...

What is the best way to add a bootstrap file to my ejs templates?

I recently installed bootstrap using npm with the command 'npm -bootstrap@3'. However, when attempting to include the bootstrap.min.css file from node_modules in my application, I encountered an error message on my console. Here is a screenshot o ...

Tips for changing text color based on background dynamically in Bootstrap SASS?

Here's a thought-provoking query for those who have experience working with Bootstrap 4 sass. According to Bootstrap's documentation, when the parent block has the class .bg-dark, adding the .text-light class to the HTML is essential for achievin ...

Angular2 progress bar with linear gradient color that visually represents progress

Seeking assistance with designing a UI progress bar for tracking the progression of an HTTP call. I am not very experienced in this area and would appreciate some example code to help me achieve the implementation shown in the attachment. I am utilizing P ...