Implementing a search input function similar to TripAdvisor's features

I want to create a search form similar to TripAdvisor's design, but I am facing some issues. The first photo shows my search bar with the class name "asdf" for testing purposes. https://i.sstatic.net/832sr.jpg

In the second picture, we encounter an issue where the expandable part of the form is wider than the input search field. https://i.sstatic.net/8qbuU.png

The third image depicts another issue when trying to assign the same width to the input["text"] field in the search form as the rest of the form.

https://i.sstatic.net/WjHoe.png

Below is my basic HTML and CSS code:

HTML

     <div class="aboutUs">

            <div class="textFlexContainer">>

             <div class="text-box">
                <h1 class="heading-primary">
                    <span class="heading-primary-main">City</span>   
                    <span class="heading-primary-sub">is where summer happens</span>   

                </h1>
              
                
                <form class="search-box" action="/search">
                  <input class="asdf" type="search" placeholder="Explore City">
                  
                    
                  <div class="search-page">
              
                    <h3>Explore City</h3>
                
              
                      <ul class="search-menu-list">
                
                      <li><a href="#">Our Daily Suggestions</a></li>
                      <li><a href="#">Shopping</a></li>
                      <li><a href="#">City Tours</a></li>
                      <li><a href="#">Restaurants</a></li>
                      <li><a href="#">Events</a></li>
                      <li><a href="#">Things to do</a></li>
                  
                    </ul>
                
              
                <h3>Recently Reviewed</h3>

              </div>
              </form>
            </div>

                  

                </div> 
                
              </div>

CSS

    .search-box{
  display: block;
  position: relative;
  overflow: hidden;
  z-index:15;
  padding:2rem;
  
  
}

.asdf {
  
  width: 80%;
  padding:2rem;
  border: none;
  outline: none;
  border-bottom:2px solid white;
  margin-top:2.5rem;
  font-size: inherit;
  background-color: green;
  
 
  color: #fff;
  
}


h3{
  color:#fff;
  margin-top:2rem;
}

.search-page {


  height: fit-content;
  background-color:green;

 
  
 
  text-align: center;
  padding:4rem 0;
  transition: all 300ms ease-in-out;
 
  display: none;
 
  
}

.search-page.visible {
  display: block;
  transition: all 300ms ease-in-out;
  
  
}


.search-page .search-menu-list{
display:flex;
flex-wrap: wrap;
  align-items: center;
  justify-content: center;
 

}

.search-page  .search-menu-list li{
  list-style: none;
}

.search-page .search-menu-list li a:hover{
  transform: translateY(-1rem);

}

.search-page  .search-menu-list li a{
  display: inline-block;
  color:#fff;
  padding:5px;
  list-style: none;
  text-decoration: none;
  margin-right: 2.5rem;
  transition: all 300ms ease-in-out;
  border: solid 2px white;
  border-radius: 1rem;
  padding: 11px 13px 11px 14px;
  margin: 10px;
  
}

.aboutUs{


  display: grid;
  background-image: linear-gradient(to right  bottom, rgba(53, 170, 120, 0.8), rgba(20, 139, 102, 0.8)) ,url(../img/ch4.jpg);
    background-size: cover;
    background-position: center;
  grid-column-start: 1; 
  grid-column-end: 13; 
  grid-row-start: 2; 
  grid-row-end: 3; 
 
  
}


.textFlexContainer{
  
    display:flex;
    align-self: center;
    
    
}

.heading-primary {
  color:#fff;
  text-transform: uppercase;
}

.heading-primary-main{

display: block;
font-size: 6rem;
font-weight: 400;
letter-spacing: 3.5rem;

}

.heading-primary-sub {

  display: block;
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: 1.8rem;

}

.text-box {
 
  display: inline-block;

  text-align: center;
  margin: auto;
  
  
  
 
}



Additionally, I would like the letters above the search bar to not get squeezed at the top when clicking on the search bar field and expanding the form.

Answer №1

Not quite sure what you're looking for, but I have a solution for fixing the alignment issue with image 3 on your .search-page. By adding just two lines of code, you can ensure that everything lines up perfectly.

    .search-page{
  height: fit-content;
  background-color:green;
  width:80%;
  text-align: center;
  padding:4rem 0;
  transition: all 300ms ease-in-out;
  display: all;
}

Setting the width to match the size of the input field in the form will help align everything properly. Additionally, using margin: 0 auto; is a simple way to center elements in CSS.

Answer №2

The expandable section seems to be hidden in the code you provided. Have you considered adjusting the width and using a margin-left to properly align it with the search 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

Align text vertically alongside radio inputs

I'm working on incorporating two radio buttons in a form. I have successfully added text inside the buttons and customized them using labels. However, despite applying text-align=center;, the text remains at the top of the button instead of being vert ...

Encountering missing static files while setting up a Blazor/Maui Server App in VS2022 for MacOS deployment

When creating the Blazor Server template on VS2022 for Windows, everything runs smoothly. Publishing to a folder and targeting Windows allows me to open the app on another Windows machine without any issues. However, when I publish to a folder and target O ...

Adjusting the audio playback time with currentTime in HTML5

Recently, I created a HTML5 player that streams music from my server. The player functions flawlessly when playing songs from the beginning. However, when I attempt to play a song from a specific time using the currentTime attribute, nothing happens and th ...

Bootstrap only allows for styling the border row and outside of a table

I'm looking to remove the vertical border of a table using bootstrap, except for the outside border as illustrated below. https://i.sstatic.net/RYq7o.png I've attempted to achieve this by: <table class="table no-footer worker-data tabl ...

How can data be partitioned into individual td elements in Rails after a specific number of records?

Revamped solution: I made some changes to the original answer that guided me in the right direction. Here is my updated code snippet: <table class="fixed"> <tr> ...

What method is most effective for comparing two HTML pages that contain identical content but varied markup?

I'm in search of a method to analyze two HTML pages for content. Both pages were created with React, but they have different structures. Nevertheless, the text within these pages is identical. What would be the most effective approach for comparing th ...

What is the best way to eliminate excessive spacing between two containers in mobile view?

I have created a layout with a single container and a row split into two columns. The left column contains a title and the right column contains a card, both centered. I am facing an issue when viewing it on mobile, there is excessive spacing between the t ...

Is there a way to customize the look of the close button on a Bootstrap 5 search box?

I am currently in the process of designing a blog template using Bootstrap 5. While working on creating the search box, I encountered a minor issue. The code snippet below has provided me with a small close button: .input-group-append .btn { border-bot ...

Issue with background image not resizing or repeating correctly on mobile devices

My website header is not scaling properly on mobile devices, causing some issues. The background color with white text using Bootstrap and custom CSS is not extending across the screen on smartphones or when viewed in Chrome Dev Tools. As a result, two ma ...

I am experiencing difficulty with my grid as it refuses to center elements

Hello everyone, this is my first post here. If I missed any important information or didn't present things correctly, please feel free to let me know. I'm currently a developer in training and recently had to work on my first website project aft ...

Blank canvas for exploring SQL and PHP queries

I am currently working on a website that displays personal statistics for users. To achieve this, I am utilizing PHP to retrieve data from an SQL database. Below are the two files I am using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...

Display a jQuery loading window

Need help with displaying a loading div when making an ajax post request. I've tried the following code but it's not working. Can someone please assist in resolving this issue? $(document).ready(function() { $('a.pagerlink').click( ...

Twists and turns as I mix up Kineticjs

After scrambling my puzzle, I now need it to be rotated. Can anyone help me with this? Thanks :) fillPatternImage:imageObj, x:-pieceWidth*i/2, y:-pieceHeight*j/2, stroke: "#000000", ...

What is the process of submitting a form using ajax .done() method after preventing the default event?

While validating my form with ajax, I am specifically checking if the username and password entered are correct. If they match, the form should be submitted and redirected to the welcome page; otherwise, an error message should be displayed. Although ever ...

Inquiring about the usage of div elements in constructing an HTML webpage

When designing my own web pages, I consistently encounter issues with using divs for a multi-column layout. Despite utilizing the float attribute to align columns left or right, resizing the browser window often causes them to stack on top of each other an ...

The Jquery function for setting the active navigation tab based on the URL is currently over-selecting and choosing more options

I have a customized Jquery function that assigns the 'active' class to my navigation anchors based on the URL. While this function generally works, the issue arises when tab 1 is active - tabs 10, 11, and 12 also get marked as active. The code s ...

"Efficiently Triggering Multiple Events with One Click in JavaScript

Hey everyone, I could use some assistance. I'm trying to execute multiple events with a single click. Currently, I can change the image in my gallery on click, but I also want to add text labels corresponding to each image. Whenever I click on a diffe ...

Navigating the Basics: Understanding the Four Quadrant Selection Grid in a Material UI & React Pop-Up Form

Sorry if these questions seem silly. I'm diving into React & Material-UI without a mentor to guide me, relying on documentation and tutorials. Is there a better place for quick beginner questions? Maybe a chat forum or Slack group? Not sure if Stack i ...

[SCSS] I am experiencing difficulties with loading fonts on my machine/browser, while they are functioning normally on other devices

When using relative paths, fonts may not load properly. However, absolute paths seem to work without any issues. //styles.scss @font-face { font-family: 'Roboto-Bold'; src: url('../fonts/Roboto-Bold.ttf'); } @font-face { font-fam ...

What is the best way to ensure that a Flex div and its child images stay confined within the boundaries of its parent container?

I'm struggling to create a responsive grid of images. I can't get the images to be both responsive with max-height and max-width, while also making sure the parent div takes up their full width. On the other hand, if I make the parent div the cor ...