Bootstrap triggering unexpected behavior in navbar styles

As I delve into the world of HTML, CSS, and JS, I encountered a peculiar error while using Bootstrap that seems to be affecting the links in my navigation bar.

Here's the CSS I've been using: https://pastebin.com/naVZuzaG

And here's the code snippet for the contact page featuring a Bootstrap Forms-component for testing purposes: https://pastebin.com/dGGPxhNT

On line 34, there's a field for entering your email that seems to be causing the navigation links to display strangely (they appear from the top right when the page loads):

      <input type="email" class="form-control" id="inputEmail" aria-describedby="emailHelp" required/>

Curiously, this issue only arises when the page is accessed online; when viewed locally on my machine, this error doesn't manifest. Any insights on why this occurs and how to prevent it would be greatly appreciated.

/* CSS styling for the top navigation bar */
.topnav {
    overflow: hidden;
    background-color: black;
}
.topnav img {
    position: relative;
    float: left;
    padding-top: 7px;
    padding-left: 20%;
}
.topnav ul {
    list-style: none;
    padding: 0px 20%;
}

/* Additional styling for links in the navbar below */
.activelink {
    background-color: white;
    color: black !important;
}
.navlist a, select {
    font-family: 'Alata', sans-serif;
    color: white;
    float: right;
    padding: 16px 20px;
    text-align: center;
    text-transform: uppercase;
    transition-timing-function: linear;
    transition-duration: 600ms; 
}
.navlist a:hover {
    background-color: white; 
    color: black;
} 

/* Main body and content styling below */
body {
    height: 100%;
    width: 100%;
    margin: 0;
    background-color: white;
}
.page-container {
    position: relative;
    min-height: 100vh;
}
.maincontent {
    padding: 30px;
}
article {
    width: 40%;
    margin-left: auto;
    margin-right: auto;
}

article small {
    text-align: center;
    padding-top: 10px;
}

/* Header styles */
h1  {
    font-family: 'Alata', sans-serif;
    text-align: center;
    padding-top: 40px;
    padding-bottom: 20px;
}

h2, h3, h4, h5, h6 {
    font-family: 'Alata', sans-serif;
    text-align: center;
    padding-top: 10px;
    padding-bottom: 20px;
}

/* Footer styles below */
footer {
    position: absolute;
    height: 3rem;
    bottom: 0;
    width: 100%;
    background-color: black;
}
footer p {
    font-family: 'Alata', sans-serif;
    color: white;
    text-align: center;
    position: relative;
    top: 50%;
    transform: translateY(-50%);
}

/* Additional styling for the contact form */
label {
    font-family: 'Alata', sans-serif;
}
.form-control {
    max-height: 300px;
}
.btn-primary {
    background-color: black;
}
.btn-primary:hover {
    background-color: white; 
    color: black;
    border-color: rgb(83, 80, 80);
}

/* Extra styling for gallery images */
#imgg {
    display: block;
    margin-left: auto;
    margin-right: auto;
}
<!DOCTYPE html>
<html>
    <!-- HTML header -->
    <head>
        <meta charset="utf-8">
    <!-- Links to stylesheets and title -->
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Alata&display=swap"> 
        <link rel="stylesheet" type="text/css" href="styles/main.css">
        <title>Testsite</title>
    </head>
    <body>
        <div class="page-container">
            <header class="header">
                <nav class="topnav">
                    <a href="index.html"><img src="images/smallogo.png" alt="Logo that says Desert Water Corp" class="logo"></a>
                    <ul class="navlist">
                        <li><a class="activelink" href="contact.html">Contact</a></li>
                        <li><a href="gallery.html">Gallery</a></li>
                        <li><a href="about.html">About</a></li>
                        <li><a href="index.html">Home</a></li>
                    </ul>
                </nav>
             
                <div class="maincontent">
                    <h1>Get in touch</h1>
                    <article>
                    <form action="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c2c5cfc1c1c9c5cdc8e4c2c5cfc1c1c9c5cdc88ac7cbc9">[email protected]</a>" method="post" enctype="text/plain" class="form-container">
                        <div class="form-group">
                            <label for="email-address">Email address</label>
                            <input type="email" class="form-control" id="inputEmail" aria-describedby="emailHelp" required/>
                            <small id="emailHelp" class="form-text text-muted"><em>We will never share your email with anyone else.</em></small>
                        </div>
                        <div class="form-group">
                            <label for="message">Message</label>
                            <textarea class="form-control" id="subject" rows="13" placeholder="Write your message here..."></textarea>
                        </div>
                    </form>
                        <button type="submit" class="btn btn-primary">Submit</button>
                    </article>
                </div>
               
                <footer id="footer">
                    <p>Copyright © 2020 Desert Water Corp</p>
                </footer>
            </header>
        </div>
    </body>
</html>

Answer №1

Kindly share some screenshots illustrating the issue and the expected outcome. Upon testing your code, I did not encounter any problems with it. This is how I perceive it using bootstrap

https://i.sstatic.net/67Ff5.png

/* Definition of the top navigation bar */

.topnav {
  overflow: hidden;
  background-color: black;
}

.topnav img {
  position: relative;
  float: left;
  padding-top: 7px;
  padding-left: 20%;
}

.topnav ul {
  list-style: none;
  padding: 0px 20%;
}


/* Styling for links in navbar below */

.activelink {
  background-color: white;
  color: black !important;
}

.navlist a,
select {
  font-family: 'Alata', sans-serif;
  color: white;
  float: right;
  padding: 16px 20px;
  text-align: center;
  text-transform: uppercase;
  transition-timing-function: linear;
  transition-duration: 600ms;
}

.navlist a:hover {
  background-color: white;
  color: black;
}


/* Main body style and main content styles below*/

body {
  height: 100%;
  width: 100%;
  margin: 0;
  background-color: white;
}

.page-container {
  position: relative;
  min-height: 100vh;
}

.maincontent {
  padding: 30px;
}

article {
  width: 40%;
  margin-left: auto;
  margin-right: auto;

/* CSS only */
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">


<div class="page-container">
  <header class="header">
    <!-- Top navigation on the webpage-->
    <nav class="topnav">
      <a href="index.html"><img src="https://picsum.photos/40" alt="Logo that says Desert Water Corp" class="navbar-brand logo"></a>
      <ul class="navlist">
        <li><a class="activelink" href="contact.html">Contact</a></li>
        <li><a href="gallery.html">Gallery</a></li>
        <li><a href="about.html">About</a></li>
        <li><a href="index.html">Home</a></li>
      </ul>
    </nav>
    <!-- Main content section -->
    <!-- Bootstrap contact form -->
    <div class="maincontent">
      <h1>Get in touch</h1>
      <article>
        <form action="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="91f7f0faf4f4fcf0f8fdd1f7f0faf4f4fcf0f8fdbff2fefc">[email protected]</a>" method="post" enctype="text/plain" class="form-container">
          <div class="form-group">
            <label for="email-address">Email address</label>
            <input type="email" class="form-control" id="inputEmail" aria-describedby="emailHelp" required/>
            <small id="emailHelp" class="form-text text-muted"><em>We will never share your email with anyone else.</em></small>
          </div>
          <div class="form-group">
            <label for="message">Message</label>
            <textarea class="form-control" id="subject" rows="13" placeholder="Write your message here..."></textarea>
          </div>
        </form>
        <button type="submit" class="btn btn-primary">Submit</button>
      </article>
    </div>
    <!-- Footer -->
    <footer id="footer">
      <p>Copyright © 2020 Desert Water Corp</p>
    </footer>
  </header>
</div>




<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c5c435c5c495e02465f6c1d021d1a021d">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

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

Animating Elements with CSS and HTML

Struggling with my website project, specifically creating a login page. The issue arises when resizing the browser, causing elements to look misaligned and chaotic. Before: view image here After: view image here /* Bordered form */ form { margin-l ...

Error encountered using Meteor 1.3 autoform/quickform integration

Having recently transitioned to using Meteor 1.3, I've encountered a few challenges related to debugging due to missing imports or exports in tutorials. This particular issue seems to be in the same vein. I wanted to incorporate the autoform package ...

Ensure that the standard icon is properly aligned with the stacked icon of equal size

Seeking guidance on aligning two icons to be the same size. Here is what I'm aiming for: https://i.sstatic.net/SHuH9.png However, in current development, they appear like this: https://i.sstatic.net/crfdl.png When attempting to resize the stack ic ...

Troubleshooting overflow problems when centering a UL menu with an unspecified width

Trying to create a demo where the scrollbars are removed when resizing smaller, but adding overflow: hidden causes issues with sub-menus. Demo Link HTML <nav> <ul> <li><a href="#">Menu Item</a></li> ...

Switching the placement of my menu bar to the other side of my logo

Can anyone help me figure out how to move my menu bar to the opposite side of my logo? I attempted using the position relative in CSS but it didn't reposition correctly. I've included the position:relative in the CSS code of my HTML index file, ...

Web Components Vanish Without Warning

I attempted to insert the HTML code for a button into my main index.html file after a specific line, but I encountered a strange issue. While the button displayed correctly, the homepage of my website suddenly vanished without any explanation. Here is the ...

Top-notch java tool for caching and minifying dojo, jquery JavaScript, and CSS files

In our project, we have downloaded the Dojo and jQuery libraries from Google CDNs. I am currently seeking a Java tool that can both cache and minify these libraries. The caching process should take place within the ROOT project of Tomcat. While I am awar ...

Showing content in a way that spaces out below the text

Could someone assist me with a CSS problem I'm having? I understand CSS, but debugging is not my strong suit. When I use display: inline-block for both my Academic Information and Personal Information, I'm getting extra white space below (above " ...

JavaScript for Dynamic Scaling Animations

I am currently working on animating an SVG button and I am trying to incorporate the transform property with a fadeout using opacity attributes in Javascript. This is how I have attempted to write the code: (Starting with opacity 0 and scale 0) (I am awa ...

How can I clear all jQuery toggled classes that have been added across the entire webpage in an Angular project?

Upon clicking a link within an element, the following CSS is applied: <a class="vehicleinfo avai-vehicle-info-anc-tag" ng-click="vehicleInfo($event)">Vehicle Info <span class="s-icon red-down-arrow"> </span> </a> $scope.vehic ...

When filling options within an optgroup in a selectbox, the data for each option may override one another

UPDATE: I made a change in my code: $('select[name=productSelect]').setOptions(["All products|ALL", "Products visible to all|VISIBLETOALL=1"]); I updated it to: $('select[name=productSelect]').prepend(["All products|ALL", "Product ...

Do you mean using a JSON object as a value?

When creating a JSON object where the value itself is an object, what is the correct way to write it? var data ='{"phone":{"gtd": "080"}}'; OR var data ='{"phone":"{gtd: 080}"}'; This question may seem straightforward. I am curious ...

Issue with spacing when assigning a JavaScript array variable to a value within input tags during a loop

Having some trouble with JavaScript code where the value is not passing in its entirety if there are spaces between the words. How can I make sure the full string or array object gets passed into the input tag's value? This is how I am trying to assi ...

Application of id missing on all buttons in Bootstrap tour template

I'm having an issue with applying a new id to the next button in a Bootstrap tour template. I added the id to the button, but it only seems to work for the first stage and not the subsequent ones. Can anyone provide insight into why this might be happ ...

Unique style sheet for unique content block

Recently I made some custom modifications to a block by adding style attributes directly into the .phtml file between tags. Now, I am looking to create a separate file for my block so that it can use a custom .css file. Where should I place this new file? ...

Is it possible to nest a <div> element inside a table in HTML code?

I am facing a requirement where I need the table rows inside a table, excluding the head row, to be scrollable. I attempted the following code, but it did not produce the desired outcome: <table id="applicantList1" border="1" align="left"> &l ...

Capturing and saving location data without internet connection, and then displaying markers once connectivity is restored

I am currently developing a web application that will monitor the user's location. I want to ensure its reliability, so even if the user loses internet connection, the application will continue tracking their location (since GPS does not rely on inter ...

Using Python, Selenium, and Beautiful Soup to scrape LinkedIn data while being logged in and accessing user accounts

I have reached a point in my script where I am able to access a search page of profiles on LinkedIn. However, I am encountering difficulty in actually accessing these profiles. When attempting to view a profile, LinkedIn displays a message stating "You d ...

Using AJAX to store values from PHP SESSION into form inputs with POST data

Wondering how to store ajax-sent data from form inputs as session variables? I have already included session_start() in header.php. Saving the code in the database is working fine. Here's what I attempted: HTML form <form action='' meth ...

Closing the Bootstrap 5 Navbar on Click Event

I'm not very familiar with Bootstrap and I came across this code online that involves javascript in html, which I don't fully understand. I want to make the hamburger menu close automatically after selecting an item in the navigation bar, especia ...