Navigation bar designed to display horizontally

In my React app, I have implemented a navbar using the provided code. It looks great on wide browser windows, but once it goes below the navbar-expand-lg breakpoint, the icons start stacking vertically. How can I prevent this behavior? (refer to the screenshot below code)

import React, {Component} from 'react';
import {
  Badge,
  Nav,
  Navbar,
  NavbarBrand,
  NavbarToggler,
  NavItem,
  NavLink,
} from 'reactstrap';
import FontAwesome from '@fortawesome/react-fontawesome';

class Header extends Component {

  constructor(props) {
    super(props);
  }

  render() {
    return (
      <Navbar dark color="dark" expand="lg" className="w-100 p-1">
        <NavbarToggler className="d-flex"/>
        <NavbarBrand className="ml-3" href="/">Logo</NavbarBrand>
        <Nav className="d-flex ml-auto" horizontal="end" navbar>
          <NavItem>
            <NavLink href="#">
              <FontAwesome icon={["fas","bell"]} className="text-light" size="lg" />
              <Badge pill color="danger">5</Badge>
            </NavLink>
          </NavItem>
          <NavItem>
            <NavLink href="#">
              <FontAwesome icon={["fas","clipboard"]} className="text-light" size="lg" />
              <Badge pill color="warning">5</Badge>
            </NavLink>
          </NavItem>
          <NavItem>
            <NavLink href="#">
              <i className="icon-location-pin"></i>
              <Badge pill color="info">5</Badge>
            </NavLink>
          </NavItem>
        </Nav>
        <NavbarToggler className="d-flex ml-3"/>
      </Navbar>
    );
  }
}

export default Header;

https://i.sstatic.net/ckPjw.png https://i.sstatic.net/ROn2m.png

Answer №1

In order to accomplish your desired layout, you will need to utilize the flex-row class to transform a typical flex column into a flex row.

Below is the complete code for your navbar, which includes both hamburger menus (the right menu items are hidden on lg screens using the d-lg-none class):

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <button class="navbar-toggler mr-3" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <a class="navbar-brand" href="#">Navbar</a>

    <div class="ml-auto order-lg-last">
        <ul class="navbar-nav flex-row">
            <li class="nav-item pr-3 pr-lg-0">
                <a class="nav-link" href="#">
                    <i class="fa fa-bell" aria-hidden="true"></i>
                    <span class="badge badge-pill badge-danger">5</span>
                </a>
            </li>
            <li class="nav-item pr-3 pr-lg-0">
                <a class="nav-link" href="#">
                    <i class="fa fa-envelope" aria-hidden="true"></i>
                    <span class="badge badge-pill badge-warning">6</span>
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">
                    <i class="fa fa-telegram" aria-hidden="true"></i>
                    <span class="badge badge-pill badge-primary">8</span>
                </a>
            </li>
        </ul>
    </div>

    <button class="navbar-toggler ml-3" type="button" data-toggle="collapse" data-target="#navbarSupportedContent2" aria-controls="navbarSupportedContent2" aria-expanded="false" aria-label="Toggle navigation2">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="#">Left Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Left Link 1</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Left Link 2</a>
            </li>
        </ul>
    </div>

    <div class="collapse navbar-collapse" id="navbarSupportedContent2">
        <ul class="navbar-nav mr-auto d-lg-none">
            <li class="nav-item active">
                <a class="nav-link" href="#">Right Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Right Link 1</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Right Link 2</a>
            </li>
        </ul>
    </div>
</nav>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

The padding adjustments for the icons on the right are made through the classes pr-3 pr-lg-0, specifying zero or default padding on lg screens and 3 units of right padding on smaller screens.

Additionally, observe how the order-lg-last class rearranges elements on lg screens and above.

Answer №2

Simply swap out navbar-expand-lg for navbar-expand

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

Customizing Material UI: A guide to updating default color schemes

Wanting to update the primary and secondary colors of my application. Despite following the instructions in the manual, I am still seeing the default blue and red colors in my app. I've been using this guide as a reference https://material-ui.com/cus ...

Conditional Rendering with Next.js for Smaller Displays

I've implemented a custom hook to dynamically render different elements on the webpage depending on the screen size. However, I've noticed that there is a slight delay during rendering due to the useEffect hook. The conditionally rendered element ...

Utilizing properties and applying styles to functional components in React

I'm facing some difficulty in correctly utilizing material UI styles and passing props to my functional component. Here's what I currently have: import { withStyles } from '@material-ui/core/styles'; ..... const styles = { media: ...

Ensure that the script continues to run uninterrupted even after the user has navigated away from the

Currently, I am working on an application that allows users to purchase tickets for events using technologies such as node.js, express.js, sequelize, and react. After the user completes the ticket purchasing process, they are redirected to a page indicati ...

jQuery code unable to alter the class of a div

Need help with a script on my single page site that adds a "read more" style link to a content area's div. The goal is for the button to change the class of the content area when clicked, showing all of the content. Clicking again should hide the cont ...

Iterating over elements with a custom width using ngFor in Bootstrap

I'm currently using *ngFor to cycle through multiple images as the background of each column in a row using Bootstrap. One thing I'm wondering is how to control the width of each column. For example, if I have 10 images, how can I adjust the widt ...

Looking for a logo placed in the center with a top fixed navigation using Bootstrap

I am in need of a Centered Logo using Bootstrap fixed top navigation. The goal is to have the brand centered within the navigation. Check out my Sample Fiddle .LandPageNavLinks { list-style-type:none; margin:0; padding:0; } .LandPageNavLin ...

Using CSS to target the first element of a type that is not a sibling

Here is my current code structure: <div> <div class="container"> <div class="title-container"> <h4 class="title blue">blue</h4> </div> <p>Something blue no 1</p> </div> <div clas ...

What are some ways to conditionally implement dynamic imports?

Currently, I am working on a project that involves Reactjs + Nextjs. I am facing a situation where I need to dynamically import a component based on certain conditions. For example: const importMyComponent = isLiveBlog => ({ image: isLiveBlog ? i ...

The build size of create-react-app is substantial, exceeding 2 megabytes in size

While using the original create-react-app to build without ejecting, I noticed that the resulting build size is quite large at 2MB. Is this a normal size for the build? I removed 'window.REDUX_DEVTOOLS_EXTENSION_COMPOSE' even though I don't ...

Issue with sticky positioning not functioning properly with overlapping scrolling effect

When the user scrolls, I want to create an overlapping effect using the 'sticky' position and assign a new background color to each div (section). However, despite setting 'top' to 0 for the 'sticky' position, the divs still s ...

Changing color of Font Awesome Icons upon hover, without any animation

I need assistance with changing the color of font awesome icons on hover without any animation. Specifically, I want the icon colors to transition from indigo to blue and finally red when a user hovers over them, without the colored icon appearing abruptly ...

What advantages could learning ReactJS first give me before diving into NextJS?

Just mastered TS and now faced with the decision of choosing a framework. I'm curious why it's recommended to learn ReactJS before NextJS. I've read countless articles advising this, but no one seems to delve into the reasons behind it. Ca ...

Troubleshooting problem with CardMedia in React Material UI

https://i.stack.imgur.com/wefd2.png Whenever I use CardMedia to display images on my website, I encounter a peculiar issue. The images do not show up on the home page initially and some errors occur. However, if I navigate to other pages or use the ' ...

Adding a splash of color to a see-through image in the Yet-Another-React-Lightbox

I am currently working on implementing a react lightbox in NextJS, and I have a specific requirement to set the background color for a PNG image. Here is my Lightbox component setup: <Lightbox plugins={[Zoom]} open={open} closeOnBac ...

Challenge encountered when applying Box Shadow to SVG using CSS

Could you kindly review this demonstration and advise me on the steps to apply box shadow to an SVG using CSS? I have already experimented with the following: .kiwi { fill: #94d31b; box-shadow: 10px 10px 5px #888888; -webkit-filter: drop-shadow( - ...

Looking to showcase API images in a three-column layout?

I have a challenge with displaying images fetched from an API in the browser. I intended to show them beautifully in 3 columns, but after implementing react semantic UI's Grid and react-bootstrap's CardColumns, they all appear in just one column. ...

Is there a way to dynamically access BEM-style selectors using CSS modules?

For instance, I have this specific selector in my App.module.css file: .Column--active I want to access this selector from the App.js file in React using CSS modules. After importing all selectors from the CSS file as import styles from './App. ...

Incorporate SVG files into a TypeScript React application using Webpack

I am trying to incorporate an SVG image into a small React application built with TypeScript and bundled using Webpack. However, I am encountering an issue where the image is not displaying properly (only showing the browser's default image for when n ...

Tips for positioning ngb-timepicker in a column with perfect alignment

I am currently working on a time picker component in Angular 8, using bootstrap 4. I have been trying to center the ngb-timepicker within a col-12 inside this specific component. <div class="row pickerContainer"> <div class="col-12 pickerCente ...