How come the sticky header isn't functioning within form tags with Bootstrap 4?

Why are the form inputs or buttons overlapping my navigation header? Everything works fine when I don't use bootstrap 4.

I need the header to always be on top of all elements in my website.

Is there a way to resolve this using only Bootstrap without involving additional Javascript?

Error Image:

window.onscroll = function() {myFunction()};

var header = document.getElementById("myHeader");
var sticky = header.offsetTop;

function myFunction() {
  if (window.pageYOffset > sticky) {
    header.classList.add("sticky");
  } else {
    header.classList.remove("sticky");
  }
}
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

.top-container {
  background-color: #f1f1f1;
  padding: 30px;
  text-align: center;
}

.header {
  padding: 10px 16px;
  background: #555;
  color: #f1f1f1;
}

.content {
  padding: 16px;
}

.sticky {
  position: fixed;
  top: 0;
  width: 100%;
}

.sticky + .content {
  padding-top: 102px;
}

.form-control {
width: 40%;
}
<div class = "container-fluid">
<div class="top-container">
<h1>Main Header</h1>
<p>Keep scrolling to observe the sticky effect.</p>
</div>

<div class="header" id="myHeader">
<h2 class = "navbar fixed-top">Navigation Header</h2>
</div>

<div class="content">

<div class = "row">
  <div class = "col-sm-12">
    <form action = "#" method = "post">
      <div class = "form-group">
        <label>Name:</label>
         <input type = "text" name = "name" class = "form-control" />
       </div>
     </form>
</div>
</div>

Answer №1

Adjust the top position to fixed for the 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

What role does the main fluid container play in HTML's user interface (UI)?

Struggling to comprehend the impact it has on the HTML. What does it signify when written like this? ...

Problem encountered with sending automated responses in Discord bot for updates on current events

Issue with Automated Replies in Discord.js' Functionality I'm currently developing a Discord bot using the Discord.js library in Node.js, and I've encountered a problem with the automatic replies feature. The bot's main task is to retr ...

Do these exports serve the same purpose?

Can someone help me understand why one export works while the other doesn't? I've tried to figure it out on my own but I'm stuck. Functioning Example const dataStore = new Vapi({ baseURL: 'http://domain.test/api', state: ...

Guide to vertical centering of inline elements within an inline-block using HTML and CSS

Despite reading numerous resources and articles on vertical alignment/centering in HTML/CSS, I still can't seem to get my specific case working as expected. If you have a moment, please take a look at http://jsfiddle.net/pf29r/3/ <div class="oute ...

argument sent to component yields a result of undefined value

I am struggling with an asynchronous method that needs to be called in order to render a value on the first cycle. However, it seems that the component is being rendered before the value is returned, resulting in the prop being undefined when passed to the ...

How can I align the kendoMenu in the center when the menu width is unpredictable?

Presenting a modified menu structure: <html class="k-webkit k-webkit40"> <head> <title>Site Title</title> <!-- js and css files referenced here --> </head> <body> <link h ...

Increasing the ID of a select input using Jquery

Is there a way to modify the identification of my select field? This select option is dynamically created using PHP. The select input can be accessed through var indirectSelect Despite its simplicity, I am facing difficulty in changing it. I attempted th ...

Utilizing jQuery to reset a toggle feature

I have created a custom clickToggle function, but I am facing an issue with it. The function currently toggles between opening and closing a div based on the clicks. The problem arises when the div is closed by clicking outside of it without activating th ...

Rails with Ajax: The destroy.js.erb file has been rendered successfully, but the specific div element identified by its id is not being successfully

Trying to implement a feature where users can click an unfollow button to end a friendship using ajax. However, the div does not disappear even though the console indicates that destroy.js.erb was rendered successfully. The expected outcome is for the reco ...

Managing input jQuery with special characters such as 'ä', 'ö', 'ü' poses a unique challenge

Hey there, I'm running into a bit of trouble with my code and I can't figure out why it's not working. Here's a brief overview: I created my own auto-suggest feature similar to jQuery UI autosuggest. Unfortunately, I'm unable t ...

Utilizing Multiple UV maps in Three.js for Enhanced Object Texturing

I'm currently exploring how to apply two different textures on the front and back of a box. The issue I'm facing is that when I scale my box (using ExtrudeGeometry), the UV maps do not update as expected. As a result, I've resorted to defini ...

How do I include a JavaScript library in Yii2 using Composer?

After successfully setting up a basic app following the steps outlined in this installation guide for Yii, I encountered a new challenge. The requirement now is to utilize q.js, which is available as an npm package. However, I am unsure of how to incorpora ...

Showing a confirmation message to the user upon clicking outside of a specific section

On my webpage, I have a section for creating content, as well as a top bar and sidebar with internal links (both controlled by ng controllers). I am looking to implement a confirmation message that will appear if the user tries to leave the page while in t ...

Guide to converting a form into a structured object format (with a tree layout)

Looking to transform a form into an object structure? <form> <input type="text" name="Name" /> <input type="checkbox" name="Feature.Translate" /> <input type="checkbox" name="Feature.Share" /> <input type="submi ...

Guide to creating fog animations in three.js

I'm attempting to adjust the fog density using tweening, but for some reason, it doesn't seem to be working. Here are my default settings: var camera, densityFog, colorFog2; colorFog2 = 0xfee2ed; densityFog ...

If I were to make 3 duplicate GET Ajax calls, would the browser wait for all three responses or process them individually?

If I were to make 3 identical calls in quick succession (within milliseconds), would the browser wait for one response or initiate 3 separate GET Ajax calls? Would it simply assign the response of one call to all 3, or is there a way to force it to do so ...

Challenges with Image Placement and Alignment

Having trouble with the sizing of my image in the skill portion of my website. The clouds and mountains look fine, but for some reason, the image isn't the same size. Additionally, the text "full stack developer" is not centered under my name anymore ...

I am wondering about the proper method for deleting multiple records simultaneously in Ember Data

My current challenge involves managing a list of record IDs, such as [1, 20, 20]. The process of individually querying and deleting each item is proving to be quite inefficient. store.findRecord('post', 1).then(function(post) { post.deleteRec ...

What is the best way to position a background image at the top of a div without overlapping the

I have this HTML code: <div class="page"> <div id="header"> ... </div> </div> Below is my CSS: .page { width: 1028px; background-color:#103250; margin-left: auto; margin-right: auto; } ...

Dynamic resizing of Bootstrap Carousel

As I delve into the realm of web design, I've encountered a puzzling issue with my BootStrap Carousel on a website project. Despite copying the code directly from the BootStrap 5.1 carousel documentation page, its behavior is rather odd, and I'm ...