What could be the reason for Chrome breaking up this straightforward bootstrap header into two lines?

Why is it that the code below displays correctly in one line in both FF and IE, but Chrome for some reason is showing it on two lines as if both span and button elements had "display:block;"? Even though the button has a computed display of "inline-block," shouldn't it be rendered next to the span instead of below it?

This behavior seems consistent with any version of Bootstrap >= 3.

Can someone explain why Chrome behaves like this?

(And I'm not asking how to place those elements next to each other - I already discovered that it works correctly when using ul and li elements)

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Test</title>
    <meta charset="utf-8">
    <script type="text/javascript" src="jquery-2.0.3.min.js"></script>
    <link href="bootstrap-3.1.1/dist/css/bootstrap.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="bootstrap-3.1.1/dist/js/bootstrap.js"></script>
</head>
<body>
    <nav class="navbar navbar-default" role="navigation">
        <div class="container">
            <div class="nav navbar-nav">
                <span class="navbar-text">User Name</span>
                <button type="button" class="btn btn-default navbar-btn">Log out</button>
            </div>
        </div>
    </nav>

</body>
</html>

Answer №1

After reviewing the documentation at http://getbootstrap.com/components/#navbar, I noticed that the class "navbar navbar-nav" is meant to be used within a ul element. As a result, I adjusted my code accordingly and found success:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Test</title>
    <meta charset="utf-8">
    <script type="text/javascript" src="jquery-1.9.1.js"></script>
    <link href="bootstrap.min.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="bootstrap.min.js"></script>
</head>
<body>
    <nav class="navbar navbar-default" role="navigation">
        <div class="container">
            <ul class="nav navbar-nav">
                <li><span class="navbar-text">User Name</span></li>
                <li><button type="button" class="btn btn-default navbar-btn">Log out</button></li>
            </ul>
        </div>
    </nav>

</body>
</html>

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

Explore/Discover feature on a website

I'm currently working on a webpage where I am querying a database and retrieving file paths. I have successfully displayed the path from the database on my page. Now, as an enhancement, I would like to add an 'Open' button next to the displa ...

Ways to prevent a div from loading an HTML page

When an external button is clicked, the remove() function on id main is triggered. The issue arises when a user quickly clicks on btn1 and then presses the external button, causing the removal to occur before the event handler for btn1. This results in the ...

problem with saving session data

I am attempting to access data from another page using session storage. On my initial page, named home.html function go_to_faq(qnum){ window.open('FAQ.html', '_blank'); sessionStorage.setItem('key2', qnum); } <a s ...

The ion-content scrolling directive is failing to show any displayed information

Within my Ionic application, I have a very simple HTML structure: <ion-pane> <ion-header-bar class="bar-stable"> <h1 class="title">Ionic Blank Starter</h1> </ion-header-bar> <ion-content> ...

The seamless integration of an HTML dropdown list in a form with a PHP email feature

Take a look at this HTML code snippet with PHP integration. How can I achieve this? I'm fairly new to coding. I'm currently developing a contact form that includes a dropdown menu for selecting an email address related to a specific physician. I ...

Design a styled rectangular tab using CSS

Does anyone know of any cool CSS techniques for achieving the tabbed rectangle appearance depicted in the image below? While it's clear that accomplishing this with just one div is not possible, is there a more efficient method than layering one div ...

How can I stop a browser from refreshing when I click the mouse?

After taking steps to prevent the browser back button from functioning by clearing history and disabling key events for page refresh, I am now seeking a way to also stop mouse clicks on the browser's refresh button. Can anyone offer assistance with th ...

What is the best way to transfer data from a div tag to an li tag using JavaScript?

https://i.stack.imgur.com/se2qk.pngI am attempting to change the div tag content to li tag. Here is a snippet of the code from inspect for reference. I need to remove the div tag with the "domTitle" class. <li style="display: inline;" id="list_name"> ...

Guide to adding an icon within an HTML `<input>` element

Is anyone able to help me successfully place my icon font inside the search input field? I've tried adjusting the margin and padding, but nothing seems to be working! If you have any insights or suggestions, please let me know. Your help is greatly a ...

NextJS's conversion of HTML to image is malfunctioning, resulting in the download of the identical reference

Having encountered difficulties with the html-to-image library while working on a Next.js project, I used the following code to convert images: import Image from "next/image"; import {toPng} from 'html-to-image' const divReferenceA = u ...

Step-by-step guide to making a circular "clip-path" work in both Internet Explorer and Firefox

Can someone help me with circle-masking in different browsers? It's working fine on Chrome. I need to make it work on Firefox and IE as well. Looking for a solution without using radius-border... .circle { -webkit-clip-path: circle(100px at 100p ...

Ways to prevent onMouseDown from triggering when the element is exclusively clicked?

I'm currently working on developing a game where units (svg elements) are controlled using React. In this game, the units should be draggable, and clicking on a unit should open a form. However, when I click on the unit, only the mousedown event is t ...

Text that is aligned vertically and centered within a div container

I need help figuring out how to make a single line of text run vertically and stay centered within its container, both from left to right and top to bottom. Any suggestions on how to achieve this using CSS? ...

Retrieving a pair of data points from a Vue <select> event when it changes

I am facing an issue with a dropdown menu that is using an array with key:value pairs. I want the dropdown to only show values, but when a selection is made, I need to pass both the value and the key using the @change event. <select @change=" ...

Automatically displaying the navigation bar upon initial loading of the HTML page

Is there a way to adjust this code so that the side nav bar remains open when the page loads for the first time? I would like the side nav to be open by default. function openNav() { document.getElementById("mySidenav").style.width = "250px"; docum ...

What is the best way to combine HTML and JavaScript code within a single JavaScript file?

Is there a way to include a responsive iframe without any scroll in multiple websites by using just one line of code? I found this snippet that seems promising: <script src="testfile.js"></script> The testfile.js contains the necessary HTML a ...

jQuery - translating and organizing names of countries

I have implemented a jQuery function to organize a list of country names based on the user's selected language code (via a language select dropdown). You can find more information on this topic in this related post. The translation of country names s ...

Tips for increasing the size of a parent div when a child div is displayed with a set width?

Is there a way to make the parent div automatically expand when the child div with a fixed width is displayed onclick? Goal: I want the child div to show up when I click the link, and at the same time, I need the parent div to expand or scale to fit the ...

React CSS Modules - Adding styles to individual child elements

I'm having difficulty applying CSS styles to each child of a specific tag. I am using CSS modules in conjunction with semantic-ui-react: character.module.css .Character > GridColumn { border: solid 4px red; } character.js import React, {Com ...

Is it possible to protect passwords internally via URL and AJAX?

During my time at a previous company, we had an internal website that required a password to be entered at the end of the URL in order to view it. I suspect this was done using AJAX, but I am unsure. Even if AJAX was used, I do not know how to code it myse ...