Positioning the menu in Bootstrap 4 with an accompanying image

I have been using the template from and I wanted to make a modification to the menu. Instead of having the blue Bootstrap 4 text, I decided to use an image in its place. Everything looked perfect until I checked it on mobile view.

The image was supposed to be in the same location as the text: https://i.sstatic.net/o0HEZ.png

However, my image ended up appearing under the hamburger menu: https://i.sstatic.net/qjz0H.png

Currently, this is how my code looks:

<nav id='topNav' className='navbar navbar-default navbar-fixed-top'>
  <div className='container'>
    <button className='navbar-toggler hidden-md-up pull-right' type='button' data-toggle='collapse' data-target='#collapsingNavbar'>
      &#9776;
    </button>
    <a className='navbar-brand page-scroll' href='#first'><img src='logo.png'/></a>
    <div className='collapse navbar-toggleable-sm' id='collapsingNavbar'>
      <ul className='nav navbar-nav'>
        <li className='nav-item'>
          <a className='nav-link page-scroll' href='#one'>Cards</a>
        </li>
        <li className='nav-item'>
          <a className='nav-link page-scroll' href='#two'>Flexbox</a>
        </li>
        <li className='nav-item'>
          <a className='nav-link page-scroll' href='#three'>5 Tiers</a>
        </li>
        <li className='nav-item'>
          <a className='nav-link page-scroll' href='#four'>More</a>
        </li>
      </ul>
      <ul className='nav navbar-nav pull-xs-right'>
        <li className='nav-item'>
          <a className='nav-link page-scroll' data-toggle='modal' title='A free Bootstrap theme' href='#aboutModal'>About</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

In order to replace the Bootstrap 4 text with the img tag: <img src='logo.png'/>, I would appreciate any guidance or assistance from someone experienced with Bootstrap.

Answer №1

To ensure a balanced layout, my recommendation is to split the hamburger and logo evenly by utilizing Bootstrap classes tailored for smaller devices (col-xs-6).

<div class="col-xs-12">
    <div class="col-xs-6">
        <button className='navbar-toggler hidden-md-up' type='button' data-toggle='collapse' data-target='#collapsingNavbar'>
          &#9776;
        </button>
    </div>
    <div class="col-xs-6">
        <a className='navbar-brand page-scroll' href='#first'><img src='logo.png'/></a>
    </div>
</div>

Answer №2

Customize the navbar-brand class to suit your logo image..

/* adjust navigation for responsiveness */
@media(max-width:48em) {
    .navbar-default .navbar-nav>.nav-item {
        float: none;
        margin-left: .1rem;
    }
    .navbar-default .navbar-nav {
        float:none !important;
    }
    .navbar-default .navbar-brand {
        float:none;
    }
    .navbar-default .navbar-brand img {
        display:inline;
    }
}

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

Crafting an innovative horizontal CSS spotlight using conic-gradient styling

Seeking advice: I need to implement three spotlights on a webpage One shining directly downwards One angled from the left to the upper-top One angled from the right to the upper-top I managed to create a vertical spotlight using CSS conic-gradient, but I ...

Animation of hand-drawn letters using SVG technology

I'm exploring SVG animations and am currently struggling with animating a slogan letter by letter. The font is handwritten and should give the effect of being written with a text marker. Can anyone provide me with some tips on how to approach this cha ...

Customizing the layout based on the device's screen size

I have been working on my personal website, and everything is almost complete except for one nagging issue. Whenever I shrink the screen size to less than 992px, the formatting of the skills section gets messed up, making everything unreadable. I can' ...

What is the updated technique for creating a full-width HTML section in 2023?

In most web designs, the content is typically "contained" to be centered and limited by a maximum width: <!DOCTYPE html> <html> <body> <div id="container" style="width: 1000px; margin: 0 auto;"> ...

Tips for creating a function to assign a CSS width using a JavaScript variable?

Here is the code snippet I have been working on: ...<script> function adjustElementSize() { var newSize = window.innerWidth - 600; document.getElementById("spin").style.width = newSize + "px"; document.getElementById("spin").style.height = newSize + ...

Media query causing CSS display:none to malfunction

I'm currently working on making my website responsive, and I have a specific requirement where I need to hide an anchor when the screen size is under 850px. The code snippet I have is as follows: My goal is to display the first anchor (#tryitnow) by ...

Blurred background images following the upgrade to Internet Explorer 11

This morning, I received an automatic update to IE 11 and noticed that some of my background images appeared blurry. After confirming that the images were not the issue, I opened Chrome and saw that they were crisp again. This left me completely puzzled. ...

Tips for avoiding tagline text overlapping with other content

I'm facing a dilemma with my Bootstrap template where my tagline overlaps all other content on the page. When I scroll down, the text lays over my logo and navbar, creating a messy look especially on smaller screens. Despite trying to adjust the z-in ...

Creating an HTML page with R Markdown: Placing an image in the upper right corner and adjusting the position of the title

Looking to add a company logo image to the top right corner of my R markdown report, and then shift the title down by 3 or 4 cm for a letterhead-like appearance. Does anyone have suggestions on how I can achieve this in my .Rmd file? Appreciate any assist ...

Hover activates a CSS animation where elements pop over other elements

I want to design a menu that resembles those "apps panels" we often see. My menu consists of 6 elements, arranged side-by-side with no space between them. When I hover over an element, it slightly pops as shown in the code snippet below: #account-bub ...

Adjustments in margins for printed HTML may vary from page to page in Internet Explorer versions 8 to 11

One challenge I'm facing is with a user-generated report page that is typically printed. There seems to be an unusual bug occurring specifically in Internet Explorer. The layout of the page consists of tables within various divs, all aligned perfectly ...

The AddClass function fails to function properly after an ajax form is submitted

I am facing a challenge in setting up validation for my ajax form. My goal is to have a red border appear around the input field if it is submitted empty. Unfortunately, when I try to use addClass(), it does not seem to have any effect. The alert message ...

What advantages does avoiding the use of float:right offer?

On my website, I have two divs - one on the left side and the other on the right side. However, the client has requested that I do not use float:right. Instead, I have opted for margin-left. What are the advantages of avoiding float:right? Is it better to ...

The image refuses to align to the left side below a floated paragraph

Hey there, I'm working on some CSS and I've run into an issue. I have two paragraphs and I want to place a picture below the paragraph on the left side. The left paragraph is longer than the one on the right, which seems to be causing the picture ...

Ways to manipulate external CSS classes with styled components without direct access

Currently, I am utilizing react-table and wanting to implement CSS rules for the class rt-td, which is not accessible or adjustable through their API functionalities. In traditional CSS practice, I could easily override the CSS class within my stylesheet. ...

Enabling overflow-y with the value of auto allows the child element to be

I'm having an issue with a parent element and a child element in my CSS code. The parent has the following properties: position: relative; overflow-y: unset; And the child has these properties: position: relative; left: -70px; Everything looks good ...

Play framework fails to apply style attributes correctly

When working with play-framework 2.3.x, I am in the process of creating a form and would like to show/hide it based on a model attribute. Typically, setting the style attribute manually using style = "display: none" and style = "display: block" works fine. ...

Trouble with partial page displaying incorrect CSS class

I have created CSS classes for generating circles with different colors. When I apply the CSS class in a regular HTML file, it displays correctly as expected. However, when I try to use it in an AngularJS partial page, the circle does not render properly. ...

jQuery Mobile - Struggling to hide a button with traditional jQuery techniques

Looking for help hiding a simple button? <input type="button" id="logoutBtn" value="logout" data-theme="d" data-inline="true" aria-disabled="false"> Attempted to hide it with this code but it didn't work: $('#logoutBtn').hid ...

What is the method for altering the look of a button using JavaScript?

As a beginner in web development, I have a question. Typically, I know how to style the submit button when it's created in the HTML page using CSS. However, I'm wondering if it's possible to apply CSS styling to the JavaScript block instead. ...