Positioning an image beneath the navigation bar in Bootstrap and CSS without it getting covered by text

I am having difficulty positioning an image below the navbar without it overlapping with the text in the navbar.

No matter what I try in my code, the image remains attached to the bottom of the navbar and won't move to a separate row below it.

I have experimented with putting the image in different containers like div, section, p, ul, li, but nothing seems to work.

Is there a way to adjust the image placement without resorting to using break tags?

    <nav id="mainNavbar" class="navbar navbar-dark navbar-expand-md fixed-top">
        <a href="#" class="navbar-brand">TEXT</a>
        <button class="navbar-toggler" data-toggle="collapse" data-target="#navLinks" aria-label="toggle navigation">
            <span class="navbar-toggle-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navLinks">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a href="" class="nav-link">Home</a>
                </li>
                <li class="nav-item">
                    <a href="" class="nav-link">About</a>
                </li>
                <li class="nav-item">
                    <a href="" class="nav-link">Projects</a>
                </li>
                <li class="nav-item">
                    <a href="" class="nav-link">Contact</a>
                 </li>
        </ul>
    </div>
</nav>
<br>
<br>
<br>
<br>

<body>
    <section>
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-5">
                    <img class="img-thumbnail rounded-circle" src="/Users/admin/Pictures/img.jpg" alt="img">
                </div>

Answer №1

When using the <code>fixed-top class, the nav element will have a position: fixed, causing the vertical height to not be filled completely. Any additional tags added will stack on top of the nav.

To address this issue, you can use a padding-top that roughly matches the height of the nav, such as 50px. This value can then be applied to subsequent tags, like

<body style='padding-top:50px'>

Alternatively, you could utilize the sticky-top class, although it may not work consistently across all browsers.

Answer №2

In my opinion, it would be beneficial to utilize position sticky over position fixed for your navigation bar

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

Another option instead of preloading images

Currently, I am in the process of creating a jQuery slideshow. After reviewing numerous tutorials on the subject, it appears that most recommend preloading images using code similar to the following: imageArray[imageNum++] = new imageItem(imageDir + "02. ...

The vertical drop-down menu is displaying and functioning incorrectly

My vertical submenu is positioned correctly, but the links are overlapping on top of each other. The submenu doesn't hide when hovering over the main menu, but it does hide when hovering outside the menu. I'm unsure of what changes or additions t ...

Leveraging an HTML form for searching and fetching data from MySQL Workbench using PHP

I'm currently working on fetching data from my database by utilizing an HTML form and establishing a PHP connection to my SQL workbench. The data retrieval is successful, as it appears at the top of my webpage. However, I am facing issues with executi ...

Using ReactJS to create cross-browser inline styling with flexbox

I'm currently working on a React web application that relies heavily on inline styling. My goal is to ensure compatibility with the latest versions of major browsers (Safari, Chrome, Firefox, IE) while utilizing flexbox for layout. The issue I encou ...

Is there a way for me to dynamically retrieve the input value produced by the Query?

Is there a way to retrieve the value of a dynamically created input field? $('#inputArea').append(" <input id = "arrivalTime1" type = 'number' placeholder='Arrival Time' style = 'display: none;'> " ...

Concealing the ellipsis in the will_paginate function of Rails

I'm currently utilizing will_paginate to manage a large number of values, but I am struggling to find a way to hide the "..." portion and the page numbers following it. Here is my current setup: https://i.stack.imgur.com/f2Tt8.jpg However, what I wou ...

Efficient PHP caching solution for optimizing JavaScript and CSS performance

I'm facing a unique challenge that I can't seem to solve through typical Google searches. I'm in the process of consolidating all my javascript and css into separate php files using require_once() to pull in the content. The structure of my ...

The hover selector in Material UI and React is not functioning as expected

My code is experiencing an issue where the hover selector does not appear to be working. Although all other styling aspects function correctly, the hover effect is not visible. import React from "react"; import Paper from '@material-ui/core/Paper&apo ...

How to Change Background Color to Black for a PNG Image Using CSS in Ionic

When applying CSS in Ionic, I encountered an issue with the background image causing the background to turn black. Without the image, everything looks fine. ion-content { --background: url("/assets/product_background.png") 0 0/100% 95% no-re ...

Guide to getting Material-UI Dialog up and running smoothly in your React application

I'm currently working on a project using material-UI, and I'm having trouble with the Dialog component not working properly. Despite trying various solutions, I haven't been able to get it to function correctly in my React application with m ...

Looking to conceal content on the navbar background using Bootstrap

From the image above, it is apparent that the text is appearing behind the navigation bar. I'm seeking guidance on how to conceal this text from the navbar when scrolling up the content. Should I create a custom CSS class with properties, or is there ...

When clicking initially, the default input value in an Angular 2 form does not get set

I am currently learning angular2 as a beginner programmer. My goal is to create a form where, upon clicking on an employee, an editable form will appear with the employee's current data. However, I have encountered an issue where clicking on a user f ...

What steps can I take to ensure that the upper and left sections of a modal dialog remain accessible even when the size is reduced to the point of overflow?

One issue I'm facing is with a fixed-size modal dialog where part of the content gets cut off and becomes inaccessible when the window shrinks to cause an overflow. More specifically, when the window is narrowed horizontally, the left side is cut off ...

Align images at the center of a division using the Bootstrap framework

I'm facing an issue with centering social network icons under a div in my login form while keeping it responsive. Can someone please assist me with this problem? Please help me!!. .row { background: #f8f9fa; margin-top: 20px; } .col { bor ...

The embedded Google iframe is causing unnecessary padding at the bottom of the page

Below is a snippet of HTML code: <div class="google-maps"> <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d109782.8671228349!2d76.62734023564995!3d30.69830520749905!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x390fee90 ...

How can you center the initial line of formatted text while keeping the rest left justified using just CSS?

I need help with formatting existing data without using JavaScript. The goal is to make the first line bold and centered, while the rest of the lines should be justify formatted. However, I'm having trouble achieving this as either the first line gets ...

Insert a percentage sign into a right-aligned text box

I am trying to figure out how to permanently display a % symbol at the far right side of a textbox that shows a percentage. Can anyone help me with this? ...

Tips for setting up a grid where boxes have a consistent width but varying heights to maximize space utilization

Seeking design inspiration from Pinterest, where fixed width columns are used but each grid item fills all available space with varying heights. Check out this example: https://i.sstatic.net/i2WDo.jpg Initially considered using flexbox for this layout, b ...

What is the best way to redirect to a specific page when logging out of a website?

To begin, let me outline the situation at hand. We have two distinct websites - website-A and website-B. Each of these websites is hosted on separate domains. A user has the ability to log in to website-B's homepage through the login page of webs ...

Convert the div into a string, including only the visible elements

Within the div #allContent, there are multiple nested divs. My goal is to extract the entire content of #allContent as a string, while excluding any invisible divs contained within it. I believe that this task can be achieved using a combination of filter ...