Troubleshooting problems with Bootstrap cards on mobile devices

I've encountered an issue on small devices with the Bootstrap card. I'm using a hover effect to slide up the content, but on small devices, the content is cutting off the image. I'm not sure how to position the content directly after the image using position: absolute. I only want to display the name and the title initially, and then reveal the rest of the content with a slide up effect on hover.

.team-card {
border:0!important;
border-radius:5px!important;
overflow:hidden!important;
}

.team-card .card-body .card-title,.team-card .card-body .card-text {
text-align:center;
margin:0;
}

.team-card .card-body {
position:absolute;
width:100%;
height:100%;
left:0;
top:255px;
background-color:#fff;
-moz-transition:all .3s ease-in-out;
-o-transition:all .3s ease-in-out;
-webkit-transition:all .3s ease-in-out;
transition:all .3s ease-in-out
}

.team-card .card-body p {
line-height:1.6em;
}

.team-card:hover .card-body {
top:0;
}

.team-card .card-body .card-text {
margin-bottom:15px;
}
<html>
<head><link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
</head>
<body>
<div class="card team-card">
  <img src="https://png.pngtree.com/png-vector/20190704/ourlarge/pngtree-vector-user-young-boy-avatar-icon-png-image_1538408.jpg" class="card-img-top" alt="">
  <div class="card-body">
    <h5 class="card-title">John Doe</h5>
    <p class="card-text">Business Director</p>
    <p>Board member (core-team) previous Director-Business Development at EM6 and earlier at Syncada.</p>
  </div>
</div>
</body>
</html

Thank you for your assistance.

Answer №1

This particular issue arises due to the usage of an absolute number in relation to the top property within the classes .team-card .card-body. A potential solution would be to set the value to top:calc(100% - 89px);, which represents the total height of the card-body minus the 89px allocated for the card-title and card-text...

Below is a functional sample:

.team-card {
  border: 0!important;
  border-radius: 5px!important;
  overflow: hidden!important;
}

.team-card .card-body .card-title,
.team-card .card-body .card-text {
  text-align: center;
  margin: 0;
}

.team-card .card-body {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: calc(100% - 89px);
  background-color: #fff;
  -moz-transition: all .3s ease-in-out;
  -o-transition: all .3s ease-in-out;
  -webkit-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out
}

.team-card .card-body p {
  line-height: 1.6em;
}

.team-card:hover .card-body {
  top: 0;
}

.team-card .card-body .card-text {
  margin-bottom: 15px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>


<div class="card team-card">
  <img src="https://png.pngtree.com/png-vector/20190704/ourlarge/pngtree-vector-user-young-boy-avatar-icon-png-image_1538408.jpg" class="card-img-top" alt="">
  <div class="card-body">
    <h5 class="card-title">John Doe</h5>
    <p class="card-text">Business Director</p>
    <p>Board member (core-team) previous Director-Business Development at EM6 and earlier at Syncada.</p>
  </div>
</div>

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

Developing a desktop app using HTML5

I'm starting out with HTML (specifically HTML5) and I'm interested in developing a desktop widget using HTML5 without having to rely on running it within a browser. Are there any software development environments available that can assist with th ...

Arranging divs using the float property

I am currently working on a Django project where I have a large list of dictionaries in the view: 'description': [ { 'name': 'Parts', 'good': ['Engine', 'Transmission&a ...

Ways to showcase a collection of divs in a dual-column layout while minimizing any unnecessary vertical spacing

Is there a way to create two columns without changing the HTML structure? The content within each child element is dynamic, so there needs to be dynamic vertical spacing as well. I'm experimenting with different CSS properties for both the parent and ...

Loading indicator for buttons

Issue with submit button onclick function (onClick="mandatoryNotes()"). It is taking a while to load, so a preloader script was added. The preloader is now working, but the function is not being called. Seeking assistance. Thank you. function mandatoryN ...

Stop Gulp Inline CSS from enclosing HTML content within html and body elements

I need to work on a piece of HTML that I plan to copy and paste directly into an existing document. Here is the code snippet: <div id="someDiv"> </div> <script src="js/someScript.js" inline></script> <style> div#someDiv { ...

What is the best way to create a unique transition for every component?

I have three elements that I would like to display with a transition effect when they appear or disappear. There is one main element and the other two show up when you click the corresponding button. You can view my current code sample here: https://jsfid ...

What is the best method for creating a distinctive identifier in HTML and jQuery?

Coding in HTML: @foreach($permission->childs as $subMenu) <tr> <td>{{$subMenu -> id}}</td> <td> &nbsp; &nbsp;{{$subMenu -> display_name}}</td> <td ...

Updating the image source attribute using Vue.js with TypeScript

Let's discuss an issue with the img tag: <img @error="replaceByDefaultImage" :src="urls.photos_base_url_small.jpg'"/> The replaceByDefaultImage function is defined as follows: replaceByDefaultImage(e: HTMLImageElement) ...

What is the reason that my "width: auto" property is not properly adjusting to the content's width?

My css code, width: auto is causing issues with the content width I am a beginner in HTML, CSS, and JavaScript, seeking help with my website. I have multiple divs within a section element, but the section's width is not adjusting to fit the divs prop ...

How can I turn off shadows for every component?

Is it feasible to deactivate shadows and elevation on all components using a configuration setting? ...

Enhancing the styling of checkboxes using CSS and Javascript

My Javascript skills have been put to the test with a simple code snippet that customizes checkboxes by hiding them and using background images in CSS to display checks and unchecks. It's a neat trick, but I'm wondering if it's HTML/CSS comp ...

CSS HTML parent div cannot contain image properly

Creating a website using Bootstrap: <div class="row padding_zero"> <div class="col section px-0"> <img class="img-trans padding_zero" src="./svg/clouds-00.svg" style="margin-top: -150px& ...

Is there a way to prevent the letters from moving when I hover over them?

What occurs when the numbers are hovered over: https://gyazo.com/20b6426d435551c5ee238241d3f96b4d Whenever I hover over the pagination numbers, they shift to the right, and I am unsure of what mistake I made in my code that's causing this. Below, I ...

Any ideas on how I can use PHP or JavaScript to repeatedly execute a segment of HTML code?

I recently tried using a for loop and heredoc in PHP with code that looks something like this: $options = ''; for($Year = date("Y"); $Year <= date("Y") + 5; $Year++) { $options .= "<option>$Year</option>\n"; } $Select = ...

As the browser window is resized, the HTML div is causing the image to be clipped

Having an issue with the dynamic resizing of Divs containing Images in my HTML Table. The Challenge: The Image within a resizable Div gets clipped at the bottom when the height decreases due to window resizing. To view the problem, visit this Example Pag ...

Angular4: Customizing Ng-Bootstrap Datepicker to Highlight Certain Days

I am struggling to figure out how to highlight matching dates in a datepicker for an array of tasks that each contain a date. Can anyone provide guidance on how to achieve this? Here is the TypeScript code snippet I have been working with: import { Compo ...

How can CSS be instructed to "apply the following most specific rule in order to determine this property"?

Utilizing Material-UI and JSS for CSS management, I've encountered an issue where styles appear differently in development versus production. The discrepancy stems from the order of rules within the file. For instance, when defining an element like ...

Exploring Bootstrap4: Interactive Checkboxes and Labels

My form design relies on Bootstrap, featuring a checkbox and an associated label. I aim to change the checkbox value by clicking on it and allow the label text to be edited by clicking on the label. The issue I'm facing is that both elements trigger t ...

Ways to implement a placeholder height for images on a webpage with varying heights using HTML

I'm facing an issue with an image on my website that has a dynamic width and height as defined by the following CSS: .sm_item_image { width:100%; height:auto; max-width:400px; } The problem arises when the image takes some time to load, ...

Traversing snapshots

My current setup involves using fancyBox, where images are wrapped in <a> tags to allow for enlargement upon clicking. However, I am facing an issue where users can navigate not only within the same panel but also between panels. Ideally, I want to l ...