Displaying both the Navbar brand and the mobile dropdown menu on the same line can be achieved

I've encountered an issue where my logo and the mobile dropdown menu won't stay on the same line when the screen size falls below a certain point. I attempted to resolve this by using media queries to resize the image, but unfortunately, the problem persists. After reading advice on another thread suggesting to set the nav-bar brand background with CSS instead of using an img tag, I tried that approach but the image failed to display.

Below is the HTML code:

<!doctype html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">

<title>Pristine Clean Outs | Home</title>

<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">

<!-- Carousel style-->
<link href="css/carousel.css" rel="stylesheet">

<!--Custom Styles-->
<link rel="stylesheet" href="css/style.css">
</head>
<body id="top">

<header>
  <div class="container-fluid">
    <nav class="navbar navbar-expand-md navbar-light fixed-top bg-white">
      <a class="navbar-brand" href="index.html"><img class="img-fluid logo" src="img/pristinelogo.png" alt=""></a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarCollapse">
        <ul class="navbar-nav ml-auto">
          <li class="nav-item active">
            <a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="about.html">About</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="gallery.html">Gallery</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="contact.html">Contact</a>
          </li>
        </ul>
      </div>
    </nav>
  </div>
</header>

Here is my CSS code:

/* Custom Styles for Pristine Clean by David Jacoby */

nav li {
  font-size: 22px;
}

.carousel-item {
  text-shadow: 2px 2px #000000;
}

.port-image {
 width: 100%;
}

.gallery_product {
 margin-bottom: 30px;

}

.contact-ul li {
   font-size: 24px;
   list-style-type: none;
}


/* MEDIA QUERIES */

@media (max-width: 768px) { 

.logo {
    width: 70%;
    height: auto;
}

}

Answer №1

Encase the brand and toggler within a flexbox div (d-flex) and utilize flex-nowrap to prevent any wrapping...

<div class="d-flex flex-nowrap w-100">
          <a class="navbar-brand" href="index.html"><img class="img-fluid logo" src="https://s22.postimg.cc/tf57x6fq9/pristinelogo.png" alt=""></a>
          <button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
          </button>
   </div>

See it in action here:

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 are the steps to implementing imgix-js via command line?

$(document).ready(function () { var imgixOptions = { updateOnResizeDown : true, updateOnPinchZoom : true, fitImgTagToContainerWidth: true, fitImgTagToContainerHeight: true, autoInsertCSSBestPractices: true, ...

HTML - Centered layout with a constant header and footer

Imagine a layout where there is always a header at the top, a footer at the bottom, and the space between them should be filled by the content 100% (image 2). Additionally, everything in the header, content, and footer should be horizontally centered, usin ...

Is Load Order Significant in Articles?

I have been scouring the internet in search of an answer to my query but haven't had much luck finding a straightforward solution. I frequently use article classes in my projects, but I never really considered whether they load in a specific order on ...

X-Ray Rendering in Three.js and Webgl

Looking to create an x-ray effect in three.js / webgl. Something like this: UPDATE I am seeking help on how to achieve a real-time render with the x-ray effect, instead of just a static image. This can be accomplished using shaders that modify density i ...

The Bootstrap carousel slider is functioning properly, however, the images are not displaying

I am experiencing an issue with my carousel. I have been developing a project and utilizing the bootstrap-4 carousel slider. It functions properly when I run it on my localhost, displaying all the images as expected. However, after publishing the project o ...

Is there a way to verify if all the div elements are set to display as none?

If all div elements are set to display:none, I want to display a message saying "No result found" element.each(function(i, el) { if (all elements are set to display:none) { no result found } } <div class="a" data-key="a ...

When is it acceptable to use HTML within PHP without judgment?

Separating control logic from view logic is a common practice, but there are instances where using html templates can be faster and less complicated. I'm wondering where it is appropriate to use this approach. For example, functions that generate dy ...

What could be causing the issue when a form returned by a jQuery AJAX request to PHP is not functioning properly within a DIV element?

My goal is to create an interactive web page and explore newer web technologies that have emerged in the past decade. This includes PhP, jQuery, and AJAX. I have simplified the code to focus on a specific issue. The objective is to have jQuery call a PhP ...

Does adding !important to the @font-face rule validate it?

Can anyone help me with a problem I'm facing? I want to ensure that users are forced to use the web font instead of the font installed on their computers because the formatting is slightly different. I've looked into using !important but I'm ...

What is the process for inserting a hyperlink into text within a tooltip?

I have implemented a tooltip within my input field using an external component, as illustrated in the code snippet below. Within the tooltip, I am trying to include a hyperlink so that users can click on the word 'world' and be directed to anothe ...

Bootstrap: the arrangement of columns in a horizontal stack

I have a nested row with 3 columns that are stacking vertically instead of horizontally. I've tried solutions from other sources like stackoverflow but none seem to be working. <div class="jumbotron mainBar"> <div class="container ma ...

Error encountered: The Bootstrap modal() function is showing as undefined when using npm modules

Every time I attempt to call $("#myDiv").modal(), an error occurs. The error message reads: Uncaught TypeError: undefined is not a function This error has popped up in different scenarios, with various parameters being passed to modal(). Many solutions o ...

Is there a way to access a route parameter that is two levels above in Angular 11?

I am seeking guidance on how to access second-level parent routes in Angular. For instance, how can I retrieve the componentId within the AttributeListComponent when using the following nested routes: const routes: Routes = [ {path: '', redirec ...

The placement of buttons in a responsive web design

Need help with adjusting button positions in mobile mode relative to text. Tried using different position settings like absolute and relative, but buttons are not staying aligned with the text on mobile devices. Can anyone assist? .button { display: b ...

Creating a flexible grid layout in CSS without relying on any pre-made frameworks

Suppose I am working with the following HTML structure <div class="option"> <input type="checkbox" /> <label>Checkbox</label> </div> <div class="option"> <input type="checkbox" /> <label>Chec ...

What is the best way to create an Angular image slider that smoothly transitions between slides without any intermediate steps?

In my Angular application, I've successfully implemented an image slider. However, I am looking to tweak its behavior specifically when navigating between non-adjacent slides using the circular navigation buttons located below the slider. Currently, ...

Alignment in the vertical direction of two lines

I've been struggling to align some HTML elements visually the way I want. There are two lines of text followed by a link. I'm trying to get the link to be vertically centered between the two lines, rather than just after the second line. Using a ...

When a user scrolls over an element with a data-attribute,

Looking to create a dynamic header effect on scroll? I have two headers, menu1 by default and menu2 hidden with display:none. In specific sections of my website, I've added a special attribute (data-ix="change-header") to trigger the header change. T ...

A textarea with a height of zero is still visible

My goal is to create collapsible widgets within a side panel on my webpage. Overall, the functionality works smoothly. I am able to adjust the height of child divs to 0px with a transition, causing them to disappear. However, I have run into an issue wher ...

The Dropdown feature in DataTable is hidden from view in Plotly Dash because of the scrolling functionality

I'm facing an issue where the dropdowns in the last few rows of a datatable are not visible as they are being cut off. Is there a solution to make the dropdown pop above the datatable so it stays visible? Here is an example for reference. Would this b ...