What is causing my navigation bar to display menu items vertically?

I'm diving into the world of Bootstrap and I've created a menu, but it seems like the menu items are stacking vertically on the right side rather than aligning horizontally on the left. Can someone spot where I might have made an error?

Here is my HTML file:

    <html>
    <head>
        <title>Register</title>
        <link rel ="stylesheet" href="css/bootstrap.min.css"/>
        <link rel ="stylesheet" href="css/main.css"/>
        <meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=no">
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script type="text/javascript" src="js/bootstrap.min.js"></script>
    </head>
    <body>
        <nav class="navbar navbar-default " id="navbar">
            <div class="container-fluid">
                <div class = "navbar-header">
                    <a href="#" class="navbar-brand" id="text">Brand</a>
                </div>
                <ul class = "nav navbar-nav" >
                    <li><a href="" id="text"> Home <span class="caret"></span></a></li>
                    <li><a href="" id="text">Team</a></li>
                <!--    <a href="" id="text">Gallery</a>
                    <a href="" id="text">Partners</a>
                    <a href="" id="text">News</a>
                    <a href="" id="text">Contact us</a>
                    <a href="" id="text">Register</a> -->
                </ul>
            </div>
        </nav>  

        <div></div>
    </body>
</html>

This is what's in my main.css file:

#navbar{
    /*background color*/
    background-color: #4311dd
}
/*change text color to white*/
#text{
    color:#FFFFFF;
}

When I view the webpage, it looks like this:

https://i.sstatic.net/46wPN.jpg

If anyone can help pinpoint where I went astray, I would greatly appreciate it.

Answer №1

When you exclude essential components like the ones designed for the Bootstrap navbar, it's no surprise that things don't appear as expected. Make sure to include those components back in to ensure everything displays correctly.

Bootstrap 4 prioritizes mobile responsiveness from the start.

If you omit the navbar-toggler components, the display may not align well because on mobile devices, the navigation is stacked vertically.

Feel free to use this code snippet as a reference:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  
  <button class="navbar-toggler" 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>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      
      <!-- Additional dropdown menu example -->
      
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

P.S. The latest release of Bootstrap 4 is beta 3. It does come with some changes from beta 2, although none of them impact the navbar components.

Answer №2

To ensure proper alignment, it is recommended to include the navbar-expand-lg class on the <nav> element and add the mr-auto class to the ul as shown below:

<nav class="navbar navbar-default navbar-expand-lg " id="navbar">
<div class="container-fluid">
    <div class="navbar-header">
        <a href="#" class="navbar-brand" id="text">Brand</a>
    </div>
    <ul class="nav navbar-nav mr-auto" >
        <li><a href="" id="text"> Home <span class="caret"></span></a></li>
        <li><a href="" id="text">Team</a></li>
        <!--    <a href="" id="text">Gallery</a>
        <a href="" id="text">Partners</a>
        <a href="" id="text">News</a>
        <a href="" id="text">Contact us</a>
        <a href="" id="text">Register</a> -->
    </ul>
</div>
</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

How to make an HTML element draggable without the need for an ID

I am currently working on making dynamically created divs draggable. While I have successfully achieved this with pre-existing div elements as shown below: <div> This can be dragged around, but outputs cannot?! </div> the issue arises when ...

JQuery for Seamless Zoom Functionality

I am working with some divs that have images as backgrounds, and I have added a zooming effect on hover. However, the zoom effect is not smooth. Is there a way to modify the script to make the zoom effect smoother? Here is an example of my HTML structure: ...

Is it possible to rotate the caret in the dropdown 180 degrees using only CSS?

Is there a way to achieve a 180° rotation of the caret in a dropdown menu upon clicking it, creating the illusion of an animation? I would prefer to accomplish this using CSS only, without the need for JavaScript, but I am open to any suggestions. .se ...

Tips for traversing through jquery ui accordion when a single panel has been disabled

I currently have a jQuery UI accordion set up with Next and Previous buttons in each panel to navigate through the sections. Additionally, I have a select HTML element in one of the panels where I can choose an option. If Option 1 is selected, the second a ...

Position to the left with Flexbox

Currently utilizing Flex to showcase checkboxes, I have successfully met the requirements for both large and small resolutions. However, for medium resolution, the checkboxes are not functioning as anticipated. I am attempting to align all the boxes to flo ...

Utilizing inline JavaScript to automatically refresh a webpage at specified intervals and monitor for updates within a specific div element

I am currently working on creating an inline script that will automatically refresh a webpage at regular intervals and check for changes in a specific element. If the element meets certain criteria, then the script should proceed to click on a designated b ...

Implementing a CSS codepen within a React Material-UI component

I'm struggling to implement this effect on my material ui card component using react and makeStyles. I am having difficulty translating this effect to the cards, could someone assist me in simplifying it into a CSS code that can be used in MakeStyles? ...

Set the text above the image in HTML and center align it

Hey everyone, I'm new to the world of HTML and CSS. Currently, I am working on designing some text above and centering an image. Additionally, I want the text to automatically wrap if the image is too long. Thank you for your help! Below is the code I ...

Convert HTML content to a PDF file with Java

Welcome to the community! My project involves extracting data from a website containing information on various chemical substances and converting it into a PDF while preserving the original HTML formatting, including CSS styles. For example, here is a li ...

Subdomain Dilemma: Trouble with Images in Internet Explorer

Currently, I am working on creating a basic website on a subdomain. Everything appears to be running smoothly in Google Chrome except for one issue with the header image not displaying in IE8. The image link is . It seems that the problem may stem from IE ...

Begin the ul element from the left-hand side

Check out my latest JSFiddle creation: http://jsfiddle.net/alonshmiel/Ht6Ym/2409/ I'm attempting to align the ul element on the left side of the page: I've experimented with the following CSS rules: margin-left:0px; float: left; Unfortunatel ...

Creating a responsive card layout in Bootstrap 4 that utilizes the vertical space of the viewport with a scrollbar

We are working on a page that has specific requirements: The page should not have a scroll bar. The card must expand vertically to fill the remaining space, even if there is no content in the card-body. We need a scroll bar for the card-body only when the ...

Highlighting the Active Navigation Menu for the Current Page Using a Unified Header File

Is there a way to highlight the navigation menu for the current page I am visiting? header.php <div class="header-menu"> <div class="nav"> <ul> <a href="index.php"><li>Home</li> ...

What is the proper jQuery traversal method to display a single templated element?

Utilizing handlebars as the view engine for node.js, the subsequent html content is dynamically produced and repeated: http://jsfiddle.net/4Q5PE/ <div class="btnsContainer"> <div class="btn-group" data-toggle="buttons"> <label cla ...

What steps can I take to guarantee that both images and text adapt well to different screen sizes?

Is there a way I can organize my website to display 3 movies per row with the text centered relative to the image? Here is how it currently looks (the red box is just for reference, please ignore): https://i.stack.imgur.com/w2pgN.jpg Also, when I resize m ...

Every time I attempt to visit my website on a mobile device, it seems to appear larger than normal, as

After developing a responsive website and adding media queries to make it mobile-friendly, I encountered an issue. Despite my efforts, the website's width is still larger than the mobile viewport, requiring users to zoom out to view it properly as sho ...

Enhance your bootstrap accordion by incorporating stylish up and down arrows using the <accordion> element

I am currently developing a sophisticated web application using Angular and TypeScript, and I have decided to incorporate accordions in some sections. The setup for these accordions involves TypeScript/Bootstrap as shown below: <accordion> <acco ...

Unable to get spacing correct on loading page

My attempt at creating a loading page using CSS and HTML has hit a roadblock. I'm trying to show a loading bar that ranges from 0% to 100%. Despite my use of justify-content: space-between, I can't seem to get it right. I've searched through ...

Trouble with CSS3 Menu Layout and Gradient Display Issues

My task is to replicate this menu: I'm having trouble creating the gradient. Completed Why can't I see it in my code? http://jsfiddle.net/Vtr6d/ Here's what I currently have: CSS: .mainOptions{ float:left; margin:0 20px 0 20px; ...

Tips for creating a CSS triangle background on a div without relying on borders or images

I have experience creating triangles using CSS borders and images, but this time I want to achieve it using background color. Here is the image of the desired outcome: https://i.stack.imgur.com/qP3yt.jpg If anyone can assist me with this, it would be gre ...