Using the div tag to create a dropdown menu in an HTML document

I have created a search bar with a filter to provide accurate search results. The filter includes three values: areaUnit, area, and price. However, the current layout is not user-friendly as it disrupts the position of elements on the page. I would like the filter div to behave like a dropdown menu, smoothly sliding down when needed. Here is my attempt at implementing this functionality:

<form>
                    <div class="wrap">
                        <div class="search">
                            <input type="text" class="searchTerm" style="width: 700px; color:#000000; text-align: left;" placeholder="Search Houses" onclick="filterfunction()">
                            <button type="submit" class="searchButton" >
                                <i class="fa fa-search"></i>

                            </button>
                        </div>
                        
                        <div  id="filter" style="display:none; background-color:#D3D3D3;border:1px; border-style:solid; border-color:black; border-radius:5px">
                            <label for="price"style=" margin-left:75px;border:none" >Area Unit</label>
                        <label for="price"style=" margin-left:30px;border:none " >Area</label>
                            <label for="price" style=" margin-left:70px;border:none">Price</label>
                        <div>
                        <select asp-for="Input.areaunit"  style="height :50px; border-style:solid ;border-color: black;border-radius:5px; margin-left:100px;">
                            <option value="" hidden>Select area Unit</option>
                            <option value="Kanal">Kanal</option>
                            <option value="Marla">Marla</option>
                            <option value="Square Feet">Square Feet</option>
                            <option value="Square Meter">Square Meter</option>
                            <option value="Square Yards">Square Yards</option>
                        </select>
                        
                            
                           
                                
                                <input list="Input.area.list"asp-for="Input.area" placeholder="Please Select area" style="height :50px; border-style:solid ;border-color: black;border-radius:5px; margin-left:20px;">
                                <datalist id="Input.area.list">
                                    <option value="10"></option>
                            <option value="12"></option>
                            <option value="15"></option>
                            <option value="20"></option>
                            <option value="25"></option>
                            <option value="30"></option>
                            <option value="35"></option>
                            
                                </datalist>
                        
                       
                            
                           
                         <input type="hidden" name="Input.price" id="Input.price"asp-for="Input.price" />
<!-- Hidden field above-->

                                <input list="Input.price.list" id="rsInput" placeholder="Please Select price" style="height :50px; border-style:solid ;border-color: black;border-radius:5px; margin-left:20px;">
                                <datalist id="Input.price.list">
                          <option value="5,00,000"></option>
                          <option value="10,00,000"></option>
                          <option value="15,00,000"></option>
                          <option value="20,00,000"></option>
                          <option value="25,00,000"></option>
                          <option value="30,00,000"></option>
                          <option value="35,00,000"></option>
                          <option value="40,00,000"></option>
                          <option value="45,00,000"></option>
                          
                         </datalist>
                          
                            </div>
                          </div>
                      
                        
                    </div>
                    
                    
                </form>

Check out the view below:

https://i.sstatic.net/9hKug.gif

Answer №1

  1. To make your .wrap class a parent of any absolutely positioned child, add position: relative.
  2. For repositioning the filter div on top or below the search bar, apply position: absolute and adjust the position using top: 20px; (customize the value as needed).

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

jQuery divs seem to "gaze up" towards the mouse pointer

I am attempting to recreate a fascinating effect using jQuery - where "cards" move in response to the mouse cursor as if they are looking up at it. I have come across a script that almost achieves what I need, but I require the ability to control the mov ...

Sequencing animations with *ngIf in Angular 6

In my component, there are two elements that utilize the same fade animation. Only one element is visible on screen at a time, controlled by *ngIf directives for visibility management. The animation is a simple fade in/fade out effect. When the state of m ...

Iterating through an object using the forEach method (uncommon practice)

Greetings, I have the following object: data = { name: undefined, age: undefined, gender: undefined }; I am looking to iterate through each key and value pair in this object and perform an action. Here is my attempt: this.data.forEach((item: ...

Changing the way in which text is selected and copied from a webpage with visible white space modifications

After working on developing an HTML parser and formatter, I have implemented a new feature that allows whitespace to be rendered visible by replacing spaces with middle dot (·) characters and adding arrows for tabs and newlines. https://i.sstatic.net/qW8 ...

What is the best approach to calculate the number of days between two dates using React JS within a map function?

Looking for a way to calculate the difference between two dates using the ReactJs jsx map loop. Data to work with: { departureDate: '2020-07-28', returnDate: '2020-09-16', } React Component: const DaysDiff = () => { ...

Apply a CSS class to the header cells

I'm facing a challenge with adding a CssClass to a table that is generated automatically through C#. The table creation code looks like this: TableHeaderRow header = new TableHeaderRow(); cell1 = new TableCell { Text = "Brand" }; cell2 = new TableCel ...

Utilize the $setValidity function within ng-repeat to validate input fields

I am facing an issue with my form that is being repeated in an ng-repeat. Below is a snippet of the form. I need to implement custom validation using $setValidity in the controller. However, I am struggling to access input names by index in the controlle ...

Creating a fixed navigation bar on the right side using Twitter Bootstrap

I'm attempting to incorporate 4 navigation buttons on the right side of a page, which when clicked will allow me to navigate to different sections within the same page, similar to a single-page design. To achieve this, I am including the following co ...

Is it possible to upload several files using multer?

I can't seem to figure out what's wrong with my code below. I'm trying to upload multiple files, but I keep getting an "UNEXPECTED FIELD" error. I am able to upload a single file without any issues, but the problem arises when I try to uploa ...

Error encountered in jQuery's addClass and removeClass functions: Unable to read the property 'length' of an undefined value

Upon loading my page, I aim to have some of the div elements hidden initially and display only one. Here is a script that accomplishes this goal: <script> $(document).ready(function () { $(".total").click(function () { $("#pi ...

Ways to display buttons next to each other rather than in a vertical arrangement

Looking for help with a table layout - trying to get buttons displayed side by side instead of stacked. Happy with either CSS or HTML solutions, just not JavaScript. Apologies if my question isn't clear, I'm still learning! I've attempted: ...

Are memory allocations made for empty indices in Typescript Arrays?

I am faced with the challenge of replicating a segment of a server-side database for processing within a typescript web application. My goal is to access specific records by their integer ID in typescript. The issue at hand is that the indices may not be s ...

Continuous Div Carousel with Looping in jQuery

I have developed a basic carousel to cycle through a series of divs, but I am facing some issues. I want the carousel to loop continuously so that after reaching "slide 07," it goes back to "slide 01." Unlike using a carousel plugin, I prefer having an ove ...

Difficulty encountering issues with JQuery's ajax function

I've encountered different errors in FF, Chrome, and IE, but it seems like there's an issue with the data in $.ajax. Below is the code snippet. Please be gentle with feedback if I have overlooked something obvious. I've spent countless hours ...

choosing between different options within Angular reactive forms

I am attempting to create a select element with one option for each item in my classes array. Here is the TypeScript file: @Component({ selector: 'app-create-deck', templateUrl: './create-deck.component.html', styleUrls: [' ...

Sleek carousel design with optimal spacing between images

Solving the Issue Utilizing Ken Wheeler's Slick plugin has allowed me to create a carousel on my website. However, I've encountered an issue where the images inside the <a> tag aren't evenly spaced and are even overlapping in some ins ...

Discover the secret to easily displaying or concealing the form of your choice with the perfect fields

Greetings! I require assistance in understanding how to hide or display a form. Specifically, I have two forms - studentForm and EmployeeForm. When selected from the dropdown list profileType, I want the corresponding form to be displayed. I am facing an ...

Adjusting the size of an image in HTML according to its dimensions

While working on creating an online shopping mall page, I encountered an issue. A majority of the images uploaded to my database have varying sizes, so I needed to resize them all. However, when I resized them and set their heights to be the same, some of ...

What is the proper way to internally submit a form?

I am interested in the possibility of internally submitting form data. For instance, let's say I want to register an account for a website. Typically, this would involve filling out a form on the site itself. However, I am considering creating my own ...

Header appearing at the same level as post title due to overlapping

After rearranging the date header below my post title on Blogger, I encountered an issue where on the latest post, the date was overlapping with the header. Adjusting the margin or padding affected other date headers, leaving me unsure of what to do next. ...