The navigation bar in responsive view on Bootstrap 4 causes the content below it to shift

Recently I have been exploring bootstrap-4 and encountered an issue while creating a nav-bar. The problem is that in responsive view, when toggling the nav-bar it simply pushes the content below it. Is there any way to address this issue within (bootstrap-4)? Ideally, I would like the nav-bar to always remain at the top of every content without pushing anything below it.

 <nav class="navbar navbar-expand-sm bg-primary navbar-dark sticky-top">
    <div class="container">
        <a href="" class="navbar-brand">
            <img src="images/kick_ass_2.jpg" alt="" class="img-fluid img-thumbnail" style="width: 50px; height: 50px"/>
        </a>
        <button type="button" class="navbar-toggler" data-target="#mainMenu" data-toggle="collapse">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="mainMenu">
            <ul class="navbar-nav mr-auto">
                <li><a href="" class="nav-link">Home</a></li>
                <li><a href="test.html" class="nav-link">About</a></li>
                <li class="dropdown"><a href="" class="nav-link dropdown-toggle" data-toggle="dropdown">Service</a>
                    <ul class="dropdown-menu bg-primary">
                        <li><a href="test.html" class="nav-link">Service one</a></li>
                        <li><a href="test.html" class="nav-link">Service two</a></li>
                        <li><a href="test.html" class="nav-link">Service three</a></li>
                    </ul>
                </li>
                <li><a href="" class="nav-link">Gallery</a></li>
            </ul>
            <ul class="navbar-nav">
                <li><a href="" class="nav-link" data-toggle="modal" data-target="#loginModal">Login</a></li>
                <li><a href="" class="nav-link" data-toggle="modal" data-target="#signUpModal">Sign Up</a></li>
            </ul>
        </div>
    </div>
</nav>


<div id="mainSlider" class="carousel slide" data-ride="carousel" data-interval="3000">
    <ol class="carousel-indicators">
        <li data-target="#mainSlider" data-slide-to="0" class="active"></li>
        <li data-target="#mainSlider" data-slide-to="1"></li>
        <li data-target="#mainSlider" data-slide-to="2"></li>
        <li data-target="#mainSlider" data-slide-to="3"></li>

    </ol>

    <div class="carousel-inner">
        <div class="carousel-item active">
            <img src="images/kick_ass_2.jpg" alt="" class="w-100 img-hight"/>
            <div class="carousel-caption">
                <h3>Some content here</h3>
                <p>More content goes here.More content goes here.More content goes here.</p>
            </div>
        </div>
        <div class="carousel-item">
            <img src="images/shield_of_captain_america.jpg" alt="" class="w-100 img-hight"/>
            <div class="carousel-caption">
                <h3>Some content here</h3>
                <p>More content goes here.More content goes here.More content goes here.</p>
            </div>
        </div>
        <div class="carousel-item">
            <img src="images/max_payne_3_new.jpg" alt="" class="w-100 img-hight"/>
            <div class="carousel-caption">
                <h3>Some content here</h3>
                <p>More content goes here.More content goes here.More content goes here.</p>
            </div>
        </div>
        <div class="carousel-item">
            <img src="images/watchmen_smiley.jpg" alt="" class="w-100 img-hight"/>
            <div class="carousel-caption">
                <h3>Some content here</h3>
                <p>More content goes here.More content goes here.More content goes here.</p>
            </div>
        </div>
    </div>
    <a href="#mainSlider" class="carousel-control-prev" data-slide="prev">
        <span class="carousel-control-prev-icon"></span>
    </a>
    <a href="#mainSlider" class="carousel-control-next" data-slide="next">
        <span class="carousel-control-next-icon"></span>
    </a>
</div>

Answer №1

Replace 'sticky-top' with 'fixed-top'

<nav class="navbar navbar-expand-sm bg-primary navbar-dark fixed-top">

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

Incorporating and utilizing the HTML5-captured image as a point of reference

I understand that all I need to do to achieve this is insert <input type="file" id="photo" accept="image/*;capture=camera"> However, my lack of coding skills has caused issues with actually grabbing and using the image selected/taken by the user. ...

What coding techniques can be used to create dynamic animation of a log stream in javascript/css

When I have a series of events in my browser, I want to display them as a list with a smooth animation effect. As each new event comes in, I'd like the existing items to slide down gracefully, making room for the new event to fade in at the top of the ...

Is there a way for me to upload a csv file along with a password_hash

I have successfully implemented this code on my website, allowing me to upload CSV files to my database. However, I am looking to enhance the security measures by changing $item2 from a numerical password to a password_hash. ($data[1] currently represent ...

How come my counter is still at 0 even though I incremented it within the loop?

Within my HTML file, the code snippet below is present: <div id="userCount" class="number count-to" data-from="0" data-to="" data-speed="1000" data-fresh-interval="20"></div> In my Ja ...

Can this be achieved using CSS alone, without needing JavaScript?

In this scenario, there is a div with the class of some-class that can have either one or two child div elements. When there is only one child div, I want it to have a width of 100%. However, if there are two child div elements present, I want them to have ...

Images displaying correctly in Next.js development environment, but failing to load on Github Pages production site

I am currently using Next.js alongside Tailwind CSS and I'm encountering an issue while attempting to set a background image for a specific div. Oddly enough, the image appears to load correctly in development mode, but fails to display when deployed ...

What could be the reason for my post container not functioning properly?

I am facing an issue with my HTML and CSS code. The container is not displaying as expected, specifically the green bar that should appear below the image. I suspect that the container's auto attribute is causing it to overlook the content inside. Can ...

Is there a way to ensure that a child mimics the behavior of its parent when adjusting the opacity and visibility properties of both elements?

Apologies for the ambiguous title, as I am struggling to accurately convey the issue I am encountering. To clarify the problem, I have created a jsFiddle. In my current layout, all four divs have opacity: 1 and visibility: visible, while divs a and b both ...

Include the HTTP header in a GET request for an HTML hyperlink

Within my HTML code, I am using an <a> tag that will trigger a 302 redirect when clicked. However, I need to incorporate some HTTP headers into this GET request. Is there a way to achieve this without including the headers in the href attribute? Tha ...

Looking for a prerequisite for running this script?

Seeking assistance from a skilled Javascript expert. I specialize in template development and utilize a specific script to display my footer link in all the free templates I create. If someone attempts to remove the footer link, their site will be redirec ...

Preventing Jquery Append from Adding Previous Elements

I am struggling to figure out how to display the star rating for each hotel individually. I have 5 hotels, each with a different star rating. Here is my Javascript code: function GetStarHotel() { var parent = $(' p.star '), imagePat ...

JavaScript - Delayed Text Appearance with Smooth Start

I want to create a landing page where the text appears with a slight delay - first, the first line should be displayed followed by the second line. Both lines should have an easing effect as they appear. Below is a screenshot of the section: https://i.sst ...

What is the best way to use jQuery to emphasize specific choices within an HTML select element?

Seeking help with jQuery and RegEx in JavaScript for selecting specific options in an HTML select list. var ddl = $($get('<%= someddl.ClientID %>')); Is there a way to utilize the .each() function for this task? For Instance: <select i ...

Tips for removing yellow box decorations

I've noticed a yellow outline appearing on many of my input boxes when I select them. How can I remove this? Css lint is reminding me that: *:focus { outline: none; } should not be used due to outlines should not be hidden unless other visual chang ...

Using the window.prompt function to send information to specific fields in a MySQL database is not functioning correctly. I am looking for assistance with this issue

Currently, I am attempting to send some data to a server that is MySQL-based. After running the code below, it seems like there are no errors showing up in the console. Can you please review this code and let me know if you spot any issues? I would really ...

Guide to assigning values to Input<input> and Select <select> elements using Javascript

I am looking to automatically set values in an input or select tag based on certain conditions defined in the JavaScript code below. However, I am facing an issue where the data does not get reflected in the database upon submitting. Any suggestions or cod ...

The masonry reorganization is behaving strangely

I've recently started using masonry for the first time and you can check it out here: Although I have managed to set it up, I am facing some issues with its positioning of boxes when dragging items in. For example, instead of placing a medium-sized ...

Adjust the stacking order to remove focus from the text field

Currently, I am facing an issue with my search box not unfocusing when clicked. My goal is to have the search box lose focus when anything on the page is clicked, especially the background (div.bb). The elements positioned above the background are set to p ...

Ways to incorporate gentle page breaks into an HTML document

My task involves creating an XSL script to analyze various XML files that share a similar structure. The aim is to parse these XMLs and transform them into HTML pages. For longer XML documents, I want the resulting HTML page to be paginated (meaning the pa ...

Utilizing Selenium to Extract Data from ESPN Website

I am currently working on a project that involves scraping data from ESPN, performing calculations on the scraped data, and then iterating through a dataframe to process player information. While I have successfully completed this task for one player, I am ...