Unable to prevent ordered lists from overlapping with other content I attempt to place beneath them in HTML

function filterImages() {
    let input = document.getElementById('searchbar').value;
    input = input.toLowerCase();
    let images = document.getElementsByClassName('gallery');
      
    for (let i = 0; i < images.length; i++) { 
        if (!images[i].innerHTML.toLowerCase().includes(input)) {
            images[i].style.display = "none";
        } else {
            images[i].style.display = "block";                 
        }
    }
}
body {margin: 0;}

ul.topnav {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
}

ul.topnav li {float: left;}

ul.topnav li a {
  display: block;
  color: rgb(255, 255, 255);
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
ul.topnav {
    position: -webkit-sticky; /* Safari */
    position: sticky;
    top: 0;
  }

ul.topnav li a:hover:not(.active) {background-color: #111;}

ul.topnav li a.active {background-color: #ffffff;}

ul.topnav li.right {float: left;}

@media screen and (max-width: 600px) {
  ul.topnav li.right, 
  ul.topnav li {float: none;}
}
#MENSIS {
  background-image: url("Images/lady-maria-bloodborne-4k.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;  
  background-position: center;
}
.h1brain {
  border: 2px solid rgb(255, 255, 255);
  margin-top: 270px;
  margin-bottom: 100px;
  margin-right: 80px;
  margin-left: 80px;
  color: white;
}
#searchbar {
  float: right;
  padding: 6px;
  margin-top: 8px;
  margin-right: 16px;
  border: none;
  font-size: 17px;
}

input[type=text] {
   width: 30%;
   -webkit-transition: width 0.15s ease-in-out;
   transition: width 0.15s ease-in-out;
}


#list{
 font-size:  1.5em;
 margin-left: 90px;
 margin-right: 90px;
}

.games{
display: block;   
} 
div.gallery {
  margin: 5px;
  border: 1px solid #ccc;
  float: left;
  width: 180px;
  background-color: rgb(255, 255, 255);
}

div.gallery:hover {
  border: 1px solid #777;
}

div.gallery img {
  width: 100%;
  height: auto;
}

div.desc {
  padding: 15px;
  text-align: center;
}
#nostyle {
  list-style-type: none;
}

.pyrus {
  background-color: light-grey;
  width: 90%;
  border: 1px solid black;
  padding: 50px;
  position: static;
}
<!DOCTYPE html>
<html id="bakugan">
      
<head>
    <title>
        Creating Search Bar using HTML
        CSS and Javascript
    </title>
      
    <!-- linking the stylesheet -->
    <link rel="stylesheet" type="text/css" href="./style.css">
</head>
  
<body>
    <ul class="topnav">
        <li><a href="./index.html">Home</a></li>
        <li><a href="./games.html">Images</a></li>
        <li><a href="#contact">Contact</a></li>
        <li class="right"><a href="#about">About</a></li>
        <input id="searchbar" onkeyup="filterImages()" type="text"
        name="search" placeholder="Search images..">
      </ul>
      

      
    <!-- link javascript -->
    <script src="./style.js"></script>

<!-- ordered list -->

 <h1 class="pyrus">Sample Text Below Images:</h1>






<ol id='list'>
    
        <li class="games" id="nostyle"><a target="_blank" href="img_5terre.jpg"><div class="gallery">
          <img src="https://static.wikia.nocookie.net/megaman/images/d/d0/MM2AirMan.jpg/revision/latest/scale-to-width-down/250?cb=20110314220902" alt="Cinque Terre" width="600" height="400">
        </a>
        <div class="desc">airman4</div>
      </div>
      </li>
         <li class="games" id="nostyle"><a target="_blank" href="img_forest.jpg"><div class="gallery">
          <img src="https://static.wikia.nocookie.net/megaman/images/d/d0/MM2AirMan.jpg/revision/latest/scale-to-width-down/250?cb=20110314220902" alt="Forest" width="600" height="400">
        </a>
        <div class="desc">airman3</div>
      </div>
      </li>
        <li class="games" id="nostyle"><div class="gallery">
          <img src="https://static.wikia.nocookie.net/megaman/images/d/d0/MM2AirMan.jpg/revision/latest/scale-to-width-down/250?cb=20110314220902" alt="Northern" width="600" height="400">
        
        <div class="desc">airman2</div>
      </div>
      </li>
        <li class="games" id="nostyle"><a target="_blank" href="img_mountains.jpg"><div class="gallery">
          <img src="https://static.wikia.nocookie.net/megaman/images/d/d0/MM2AirMan.jpg/revision/latest/scale-to-width-down/250?cb=20110314220902" alt="Mountains" width="600" height="400">
        </a>
        <div class="desc">airman1</div>
      </div></li>
</ol>

<h1 class="pyrus">End of Sample Text Section</h1>

</body>
  
</html>

I'm attempting to ensure that the sample text appears neatly below the list of images without overlapping with other elements. I've tried various techniques such as positioning and margins but have not achieved the desired result. I want the <h1> elements to be positioned relative to the images on the page.

Answer №1

this occurs due to the use of float. If you wish to utilize float, it is necessary to include a clearfix to prevent element collapse. Learn more about this W3School clear float

To address this issue, I applied a clear float using overflow: auto; on the .pyrus class

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

Utilizing XSLT 1.0 to encase text and elements within paragraphs

After successfully solving a problem using XSLT 2.0, I now face the challenge of achieving the same outcome in XSLT 1.0 due to the requirement of using a processor compatible with XSLT 1.0. My task involves handling various types of XHTML and XML, each wi ...

Can the ajaxsetup error handler be used with the POST method?

I have a strange question - does the global error handler applied when using ajaxsetup get triggered in case of an Ajax error on a POST request? I've tried handling Ajax errors in several places, but the error handler is only being hit for GET reques ...

Upgrade your project from Angular 5 to Angular 9 using webpack

I want to share my experience, not ask a question! To upgrade dependencies in package.json: -Update all Angular dependencies to version 9 -Add these dependencies: "@angular-devkit/build-angular": "^0.900.4", "@angular-builders/cu ...

Unable to achieve separation of borders within dash_table.DataTable styling using CSS by setting border-collapse: separate; considering using border-spacing instead

Is there a way to create space between the lines of a table in dash_table.DataTable using css or regular style capabilities? I have tried using border-collapse and border-spacing but it doesn't seem to be working. How can I achieve this desired spacin ...

Traverse through an array of objects with unspecified length and undefined key names

Consider the following object arrays: 1. [{id:'1', code:'somecode', desc:'this is the description'}, {...}, {...}] 2. [{fname:'name', lname:'last name', address:'my address', email:'<a h ...

A guide to successfully sending the 'onClick' function to a child component within React

In my coding project, I have developed a versatile Modal component that can be customized with different headers, bodies, and footers, as well as various arguments for the Reactstrap components. While I am using Reactstrap to create the Modal, the issue is ...

Connecting the search results page with the specific details page

Currently, I am developing a results page for my website and require assistance with linking each restaurant to a detail.php page. The project involves showcasing all the restaurants in San Francisco along with their health inspection scores, address, and ...

Having difficulty incorporating a video into the background

After searching online and attempting two different methods, I am still unable to achieve the desired result. I want a video to cover the entire background of my webpage. Here is what I have tried: CSS - video#bgvid { position: fixed; top: 50%; ...

Communication through HTTP requests is not supported between docker containers

I currently have two applications running as services within a docker-compose environment. My React App A Node.js server In an attempt to make an HTTP request from my React app to the Node.js server, I am using: fetch("http://backend:4000/") However, w ...

Customizing Thickness for Tab Labels in MUI 5

I have been trying to adjust the thickness of the label inside a tab using MUI 5, but so far I haven't had success. Here is what I have attempted: interface TabPanelProps { children?: React.ReactNode; index: number; value: number; } funct ...

Gather information using HTMLParser

<tr> <td style="color: #0000FF;text-align: center"><p>Sam<br/>John<br/></p></td> </tr> Utilizing the python's HTMLParser module, I am attempting to retrieve the entries Sam and John from the provided ...

Eliminate gaps between items when using the flex-wrap:wrap attribute

Check out my code on Plunker. Is there a way to eliminate the vertical spacing when using flex-wrap: wrap; #main { width: 200px; height: 200px; border: 1px solid #c3c3c3; display: flex; flex-wrap: wrap; } <div id="main"> < ...

What is the reason for my JSON reference returning as undefined?

Here's my JavaScript code: $.getJSON("/aTest.json", function (jsonObj) { $("#testJSONBtn").click(function () { var val = ""; for (var i = 0; i <= jsonObj.events.length; ++i) { val += jsonObj.events[i].title + ", " + ...

Struggling to store a new user in Firebase Database

I have been researching extensively and am struggling to get any data to show up in the firebase database. I am aiming for this specific structure: "my-app-name": { "users": { "uid-of-user": { "email": "<a href="/cdn-cgi/l/email ...

Cordova - Fixed elements flicker/blink when scrolling

I have exhausted all possible solutions, ranging from -webkit-transform: translate3d(0,0,0); to -webkit-backface-visibility:hidden but none of them seem to resolve the issue of an element flickering/blinking/disappearing when scrolling on iOS with - ...

Conditionals in ng-class Syntax

I'm attempting to apply a class conditionally to an element, but I'm struggling with the correct syntax. I've experimented with the code below, but it's not functioning as expected: ng-class="{foo: bar === "true"}" The value of bar i ...

Selenium tactics: patiently awaiting the arrival of a specific element

I am fairly new to Selenium, so please bear with me as I ask some potentially simple questions. Lately, I've been exploring ways to make Selenium wait until a specific element is fully loaded within a pop-up <div>. My goal is to scroll down to c ...

Navigate quickly to different sections using jump links and adjust the positioning with the style attribute, such as "padding-top

My website incorporates Jump Links to navigate between page elements as part of an interactive User Guide. Everything functions properly on Firefox, IE, and Edge, but Chrome and Opera seem to disregard the 'padding'. Due to a fixed menu bar on t ...

What is the best way to extract a number from a string in JavaScript?

There are instances in HTML files where a <p> tag displays the price of a product, such as ""1,200,000 Dollar"". When a user adds this product to their cart, I want the webpage to show the total price in the cart. In JavaScript, I aim to e ...

What is causing the 'info' object to be undefined?

transporter.sendMail(mailOptions,(error,info)=>{ if(error) console.log(error) console.log('Message Sent: '+info.messageId) console.log('Preview URL: '+nodemailer.getTestMessageUrl(info)) res.redirect('contacts', ...