Having difficulty converting the navbar into a horizontal layout

I'm struggling to figure out how to display the navbar horizontally across the page instead of vertically. I've experimented with different solutions, but it seems like the issue lies within the ul class. Unfortunately, I haven't been able to resolve it yet.

<body>
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="/"><img src="/static/kkapital.png" align="left"></a>
            </div>
            <ul class="nav navbar-nav navbar-left">
                <li class="active"><a href="#">Home</a></li>
                <li><a href="#">Page 1</a></li>
                <li><a href="#">Page 2</a></li>
                <li><a href="#">Page 3</a></li>
            </ul>
        </div>
    </nav>
</body>

Answer №1

If you take a look at the example provided here, you'll notice that there are some changes that need to be made for your code to work correctly. The key difference lies in using the navbar-expand class, which arranges the items horizontally instead of vertically. Additionally, adding a background color with bg-light is recommended but not mandatory. Another important adjustment is including nav-item and nav-link classes for each menu item, as this helps with styling, spacing, hover effects, and overall code structure for easier customization later on.

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="/">Brand</a>
    </div>
    <ul class="nav navbar-nav navbar-left">
      <li class="active"><a href="#">Home</a></li>
      <li><a href="#">Page 1</a></li>
      <li><a href="#">Page 2</a></li>
      <li><a href="#">Page 3</a></li>
    </ul>
  </div>
</nav>
<nav class="navbar navbar-expand bg-light">
  <div class="navbar-header">
    <a class="navbar-brand" href="/">Brand</a>
  </div>
  <ul class="navbar-nav">
    <li class="nav-item active">
      <a class="nav-link" href="#">Page 1</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Page 2</a>
    </li>
    <li class="nav-item dropdown">
      <a class="nav-link" href="#">Page 3</a>
    </li>
  </ul>
</nav>

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

What is the best way to create a floating navigation bar that appears when I tap on an icon?

As a beginner in the realm of React, I recently explored a tutorial on creating a navigation bar. Following the guidance, I successfully implemented a sidebar-style navbar that appears when the menu icon is clicked for smaller screen sizes. To hide it, I u ...

Uncovering concealed data in job listings by utilizing BeautifulSoup

Hey there! Currently, I am enrolled in a python course and our assignment for today involves extracting job listings from this website: I have attached a screenshot of the HTML related to this task here: python jobs f12 This is what I have managed to com ...

In HTML, the usage of "*" and <body> element within a <style

Can you explain the distinction between * and body when used in the style tag of HTML? Providing examples would greatly aid my understanding. Thank you! ...

Positioning a Safari browser relative to a flex container

Seeking assistance with positioning elements in Safari 602.1 on iOS 10 using Bootstrap 4.1. The text isn't positioned correctly, even after auto-prefixing Bootstrap. The issue only occurs in Safari; everywhere else, it works fine and I'm at a lo ...

What is preventing me from displaying a jqGrid on my HTML page?

I am encountering some issues while trying to display a jqGrid on an HTML page. The code I have implemented is causing a run-time error, and the grid is not being loaded properly. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...

The Urdu language characters are not showing up correctly following the switch to a new hosting server

I recently switched from using Namecheap hosting servers to Site Ground for my website at . However, I encountered an issue where the Urdu language words stored in the database are not displaying correctly. Instead of showing the actual words, it is displa ...

The website is experiencing crashes in IE11 whenever the developer tools are closed

I'm experiencing an issue with my website where it crashes internet explorer if the developer tools are not opened. I have checked for console.log calls as a possible cause, but that doesn't seem to be the problem here. The error is not just di ...

Tips for retrieving specific database entries using a JavaScript function

I'm currently in the process of developing a web directory that showcases organizations based on the selected county by utilizing an XML database. During testing, I have configured it to only display organization names and counties for now. However, ...

Trouble with displaying label in PDF post HTML conversion using iText html2pdf

Software Versions: html2pdf v2.0.1 iText 7.1.1 The HTML label that spans the width of the page is as follows: <label class="test">Patient</label> CSS Styling: .test { display: block; font-weight: bold; color: #009fd1; font ...

Display the HTML content once the work with AJAX and jQuery has been successfully finished

Below are the codes that I have created to illustrate my question. It's not a complete set of code, just enough to explain my query. The process goes like this: HTML loads -> calls ajax -> gets JSON response -> appends table row with the JSO ...

Angular: Enhancing user experience with draggable and droppable items in a flexible list

My issue involves drag and drop divs within a list. However, the divs seem to move in an unpredictable manner. They do not go where I intend them to be placed. Here is the TypeScript code: timePeriods = [ '1', '2', '3', ...

Can you please explain the purpose of the white space in the HTML code?

Currently, I am working on developing a mobile application, and as I start adding styles, I notice a mysterious blank space that seems to be appearing out of nowhere. Can anyone provide any insights or suggestions to help me troubleshoot this issue? https ...

Hey there, I'm looking to make sure that my div is consistently bigger than my content, even with text that cannot wrap. Can you help me figure out how to

Behold the current appearance of my window: https://i.sstatic.net/iIxDS.png Despite my efforts to maintain proper sizing, when I shrink the screen, the text (with white-space set to nowrap) ends up looking like this: https://i.sstatic.net/uXqox.png Is t ...

Exploring the Transition from React.js with Material UI to Next.js for Server-Side Rendering: A Comparison of Tailwind CSS, Material UI, and Chakra UI

Currently, I am in the process of moving my React.js application with Material UI components to Next.js for server-side rendering (SSR) while considering some UI changes. In my research, I have come across three UI frameworks: Material UI, Chakra UI, and T ...

Utilizing CSS and Tailwind with either flexbox or grid to showcase repeated information in a layout of three rows

For a school project, I am exploring the use of CSS and Tailwind to enhance my learning. My task involves displaying data using a loop in Vue. The challenge is that this data needs to be presented in rows of 3, 2, and 3 in desktop view, while appearing sta ...

What is the best way to locate an element using text in xpath?

Having an issue with this HTML source code: <td class="specs_title"> Processortype <a href="#" class="info-link"> <img src="x.jpg" title="" height="16" alt="" width="16" /> <span class="info-popup"> <span class="hd">Processor ...

Surprising margin discrepancy of 10px found while utilizing float property in CSS

Encountered an issue with the CSS property "float". There is a 10px margin at the top of the page. How can this be fixed? I tried adding an empty div to the parent div with id="background1", but it did not work. I also found this article https://css-trick ...

To prevent the page focus from shifting, make sure to force click on a blank link

My question involves an empty link: <a href="#" id="stop-point-btn">+ add stop-point</a> This link is connected to a JavaScript function: $("#stop-point-btn").bind("click", addStopPoint); The JS function simply inserts content into a specif ...

No content in Django's Bootstrap dropdown menu

I need assistance with extracting a list of objects and placing them in a dropdown menu. I have successfully achieved this, but the issue seems to be related to my HTML structure. Here is the code snippet from my HTML: <div class="dropdown"> < ...

What's the Best Approach: Conditional Processing or Separate Pages?

I am in the process of creating a resource section on a website that will showcase various types of information, such as guidebooks, blogs, and corporate documents. Each type of information has unique requirements when it comes to layout and presentation. ...