Card Resizes when Search Button is Pressed

Recently, I've delved into Bootstrap after focusing primarily on backend development. As part of my front end work, I am implementing a feature where users can search for a place and a list of nearby venues will appear in a card layout using Bootstrap cards.

However, when I perform a search, the card suddenly shrinks to a small size with scroll bars, causing all content divs (such as map/card) to shift downwards slightly.

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

My goal is to maintain a consistent standard height for the card post-search.

Below is the initial HTML code for the card:

  <div class="card" style="width: 18rem;">
          <div class="card-body">
            <h5 class="card-title">Places Nearby</h5>
              <div id="cafes">
                <div id="cafe_list"></div>
              </div>
          </div>
        </div>

And here is the relevant HTML code for the function that generates the list:

<div class="cafe-details d-flex">
            <ul>
              {% for cafe in cafes %}
              <li>
                <address>
                  <div>
                    <h6 class="cafe-name" data-id="{{ cafe.id }}">{{ cafe.cafe_name }}</h6>
                    <p>{{ cafe.cafe_address }}</p>
                  </div>
                </address>
                <p>
                  <a href="">Add to List</a> / <a href="">Recommend</a>
                </p>
                </li>
              {% endfor %}
            </ul>
          </div>

Lastly, below is a snippet of my CSS related to the issue:

.card {
   position: absolute;
   width: 100px;
   border: 1px;
   top: 75px;
   bottom: 10px;
   left: 25px;
   z-index: 10040;
   overflow: auto;
   overflow-y: auto;
}

.cafe-details {
  position: absolute;
}

Answer №1

Eliminate the

.cafe-details {position: absolute;}
CSS rule.

.card {
  position: absolute;
  width: 100px;
  border: 1px;
  top: 75px;
  bottom: 10px;
  left: 25px;
  z-index: 10040;
  overflow: auto;
  overflow-y: auto;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">

<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
  <title>Title</title>
</head>

<body>
  <p>This is my web page</p>
  <div class="card" style="width: 18rem;">
    <div class="card-body">
      <h5 class="card-title">Places Nearby</h5>
      <div id="cafes">
        <div id="cafe_list">

          <div class="cafe-details d-flex">
            <ul>

              <li>
                <address>
                  <div>
                    <h6 class="cafe-name" data-id="some_cafe_id">some_cafe_name</h6>
                    <p>some_cafe_address</p>
                  </div>
                </address>
                <p>
                  <a href="">Add to List</a> / <a href="">Recommend</a>
                </p>
              </li>

              <li>
                <address>
                  <div>
                    <h6 class="cafe-name" data-id="another_cafe_id">another_cafe_name</h6>
                    <p>another_cafe_address</p>
                  </div>
                </address>
                <p>
                  <a href="">Add to List</a> / <a href="">Recommend</a>
                </p>
              </li>

            </ul>
          </div>

        </div>
      </div>
    </div>
  </div>
</body>

</html>

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

Centering the scrollIntoView feature on mobile devices is presenting challenges with NextJS applications

Description While navigating on mobile browsers, I'm facing a challenge with keeping an element centered as I scroll due to the browser window minimizing. I've experimented with different solutions such as utilizing the react-scroll library and ...

Guide on handling multiple forms using Ajax-PHP

My web page features two separate forms. The first form, Form1, includes various input fields for data entry. The second form, Form2, is specifically designed for uploading files to the server. When the user clicks the "Upload" button on Form2, it triggers ...

Retain the spaces within a string in Java and JavaScript programming languages

My Java code sends data to the browser via an HTTP request, and the output looks something like this: JAVA CODE OUTPUT | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | | 0 | SELECT STATEMENT | | | | 3 ...

Address the underlying issues with the background

I am working on an app and I want to include a fixed background image. I am using HTML5, CSS3, and JavaScript for this project. I have applied the CSS code to set the background image as fixed: body{ background:#1F1F1F url(../assets/bg.png) fixed;} Ev ...

Adjusting image size as you scroll

Hello everyone, I am currently working on coding a website logo that decreases in size as the user scrolls down, similar to the effect seen on this website: . I am relatively new to HTML and was wondering if there are any specific commands or techniques th ...

Learn how to dynamically disable a button using jQuery within the Materialize CSS framework

While attempting to disable a button in Materialize CSS using jQuery, I encountered an issue. Despite following the documentation found here, it seems that simply adding the 'disabled' class does not automatically disable the button as expected. ...

Replace particular letters within the text with designated spans

Suppose I have this specific HTML code snippet: <div class="answers"> He<b>y</b> <span class='doesntmatter'>eve</span>ryone </div> Additionally, imagine I possess the subsequent array: ['correct' ...

What are some strategies for increasing efficiency in my drag and drop process?

Update #2 Wow, transition was stuck at .35s. My CSS just wasn't updating properly :( UPDATE: Anyone know if requestAnimationFrame could help with this? I've got a rotating image reel and I want users to be able to swipe left or right to switch ...

jmpress: Scrolling through Absolutely Positioned Element (Slide) with dynamic height

Check out the Live Site I'm currently working on a website using jmpress, but I'm facing difficulties in implementing scrolling functionality for my content. While I can scroll in Chrome by selecting text and dragging down, I want to achieve thi ...

Tips for creating shaped images using clip-path

Can an image be clipped to match a specific shape using the clip-path CSS property? Original Image https://i.stack.imgur.com/rYeuk.jpg Desired Result with CSS https://i.stack.imgur.com/6FYfn.png ...

PHP is having trouble updating the database when multiple radio buttons are selected. It appears that only the most recent radio button selected will be updated in the database

In my form, there are 2 numbers and 4 radio buttons for each. Only one option can be selected per number. When the form is submitted, only the database for question 2 will be updated. However, if question 2 is left blank, then question 1's database w ...

How do I customize the default styling of a single slider in react-slick?

Looking to enhance the look of slick carousels by customizing prev/next arrows and controlling their position? I'm currently using nextjs13, chakra-ui, react-slick, and vanilla extract. An effective way to customize arrow styles is by passing an arro ...

Retrieve an equal number of elements from HTML with the help of rvest

I am attempting to collect data on the names of cities and addresses of all Apple stores located in the United Kingdom by utilizing the rvest package. library(rvest) library(xml2) library(tidyverse) my_url <- read_html("https://www.apple.com/uk/re ...

Having a large number of columns makes it difficult to adjust the column width

Is there a way to maintain column width when there are multiple columns present? When the user clicks the + to view additional data, the Product Type column ends up looking uneven due to width issues. I attempted to use style="width:300px;", but unfortuna ...

Is it possible to make the info box centered and adjust everything to seamlessly fit on all screen sizes?

Is there a way to create a centered info box that stretches to fit any screen size? ...

"Hovering over one div does not trigger the display of another div

I seem to have forgotten my CSS skills, but I am facing an issue. Here is the code snippet: <div class="footer_container"> <div class="website_logo_to_footerexpand"></div> <div class="info_cont"> <div class ...

Ensuring the height of the body and content div in Bootstrap 4 combined with Angular set to

Is there a way to center the <div class="card"> in the middle of the page or body? It works perfectly on a desktop browser, but on mobile view, it's not aligning properly. How can I center it using... html, body { height: 100%; background: ...

Expanding the Bootstrap Utility class within an SCSS stylesheet

Utilizing Bootstrap's utility classes in my scss file has been a recent experiment of mine. For instance: .pageTitle { @extend .p-3, border-bottom: 1px solid red} My current approach to importing Bootstrap involves using this code: @import '~b ...

Animate the X position of a div's background image to create a scrolling effect

I'm seeking to achieve something similar to the example shown here: Unfortunately, it seems that it is not compatible with the latest versions of jQuery. ...

The mobile site is extending beyond the width of the device screen

After creating this single web page and testing it on my mobile device, I noticed an issue. When I swipe to the left, the website's width shifts slightly, as if the edges are not fully contained within the screen. This problem only occurs on Safari, n ...