Images on small screens are not displaying properly on responsive cards

I've been struggling with making a card responsive for smaller screens. No matter what I try, some of the images get cut off when the screen size is reduced. I need to keep it small enough to fit on a small screen without sacrificing the appearance on medium screens. Here are my codes and some images showing the issue – big screen | small screen. Can anyone offer assistance with this challenge?

*{
  margin: 0;
  padding: 0;
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
}

h1{
  font-size: 2.5rem;
  font-family: 'Montserrat';
  font-weight: normal;
  color: #444;
  text-align: center;
  margin: 2rem 0;
}

.wrapper{
  width: 100%;
  margin: 0 auto;
  max-width: max-width: 80rem;;

}

cols{

  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-wrap: wrap;
      flex-wrap: wrap;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
}

.col{

  width: calc(25% - 2rem);
  margin: 1rem;
  cursor: pointer;
}

.container{
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
-webkit-perspective: 1000px;
        perspective: 1000px;
}

.front,
.back{
  word-wrap: break-word;
  white-space: -moz-pre-wrap; /* Firefox */    
  white-space: -pre-wrap;     /* Opera <7 */   
  white-space: -o-pre-wrap;   /* Opera 7 */    

  background-size: 400px 400px;
  background-position: center;
  background-repeat: no-repeat;
-webkit-transition: -webkit-transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);
transition: -webkit-transform .7s cubic-bezier(0.4, 0.2, 0.2, 1);

...

@media screen and (max-width: 32rem){
  .col{
    width: 100%;
    margin: 0 0 2rem 0;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- CSS only -->

...

Answer №1

/* importing font */
@import url('https://fonts.googleapis.com/css?family=Raleway&display=swap');
*{
    margin: 0;
    padding: 0;
}
body{
    margin: 0;
    padding: 0;
    background: #f1f1f1;
    font-family: "Raleway", sans-serif;
    text-align: center;
}
header{
    margin: 0;
}
a, li{
    list-style: none;
    text-decoration: none;
}
nav{
   text-align: center;
    padding-top: 15px;
    padding-bottom: 15px;
    background: white;
    width: 100%;
}
.nav-link + .nav-link{
    margin-left: 30px;
}
nav ul li + nav ul li{
    margin-right: 30px;
}
nav ul li{
    display: inline-block;
}
.products{
     padding: 30px 50px 100px 50px ;
 }
.card{
    max-width: 20%;
    background: #ffffff;
    padding: 10px;
    border-radius: 5px;
    text-align: right; display: inline-block;
    margin-left: 20px;
    margin-top: 30px;
    animation: rotation 1s ease-in-out ;
}
@keyframes rotation {
    from {
        transform: rotateY(0deg);
    }
    to {
        transform: rotateY(359deg);
    }
}
.card-body div{
    margin-top: 10px;
}
.card-footer button{
    margin-top: 20px;
    background: #fb727c;
    border-radius: 5px;
    outline: none;
    border: none;
    color: white;
    margin-bottom: 5px;
}
.product-name{
    text-align: left;
    font-size: 18px;
    font-family: "Raleway Medium", sans-serif;
}
.product-price{
    text-align: left;
    font-size: 22px;
    font-family: "Raleway Medium", sans-serif;
}
button{
    cursor: pointer;
    font-family: "Raleway SemiBold", sans-serif;
    font-size: 16px;
    padding: 8px 25px 8px 25px;
    transition: 0.2s ease-in-out;
}
button:hover{
    box-shadow: 0 5px 10px rgba(239, 60, 73, 0.5);
    transition: 0.2s ease-in-out;
    background: rgb(239, 60, 73);
}
img{
    max-width: 100%;
}
/* responsive design */
@media (max-width: 768px) {
    .products{
        padding: 30px 20px 30px 20px;
    }
    .card{
        max-width: 40%;
        display: inline-block;
    }
    .card {
        margin-left: 0;
        margin-top: 30px;
    }
}
<body>
<header>
    <nav>
        <ul>
            <li class="nav-link"><a class="nav-item" href="">Home</a></li>
            <li class="nav-link"><a class="nav-item" href="">About</a></li>
            <li class="nav-link"><a class="nav-item" href="">Service</a></li>
            <li class="nav-link"><a class="nav-item" href="">Contact</a></li>
        </ul>
    </nav>
</header>
<main>
    <div class="products">
        <div class="card">
            <div class="card-header">
                <div class="product-img">
                    <img src="https://www.nowfoods.com/sites/default/files/styles/home_site_sections/public/beauty-health-catagory-homepage_0.png?itok=wSmkgxgp" alt="">
                </div>
            </div>
            <div class="card-body">
                <div class="product-details">
                    <div class="product-name">Short denim dungarees</div>
                </div>
                <div class="product-price">
                    ₹1,900
                </div>
            </div>
            <div class="card-footer">
                <a href=""><button>Add to Cart</button></a>
            </div>
        </div>

        <!-- More similar card elements -->

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

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

Overlaying text on several images

My challenge is centering text over multiple images using a combination of Bootstrap and CSS. While most online resources suggest using position: absolute; to achieve this, I have only been successful in centering the text in the middle of the screen rathe ...

Is there a way to achieve element scrolling similar to scrollLeft within a scrollable container without using JavaScript

Looking for a CSS Solution: Is there a way to achieve element.scrollLeft functionality in CSS without using javascript? I want to pre-scroll a scrollable container. Situation Overview: I have a scrollable container that houses various items. Some instanc ...

Increasing the maximum width of an image in CSS is necessary to see the max-height take effect

Within my HTML structure: <Col md="6"> <div className="hero-section"> <div className={`flipper ${isFlipping ? "isFlipping" : ""}`}> <div className="front"> <div className="hero-section-content"> ...

What is the best way in Vue.js to preload images upon the route being loaded without immediately showing them?

Looking to implement a smooth transition effect when switching between different scenarios in a web application. The issue arises when fetching images takes time, resulting in abrupt appearance instead of a gradual transition. Seeking a solution to preload ...

Adjust the date input alignment in mobile browsers

I am trying to align the entered date to the left in input[type='date']. However, when testing on mobile browsers like safari and chrome, the date remains centered within the input. mobile example This is the code I have been working on: .co ...

Highlighting the navbar in the right-hand section

I need help with highlighting the navbar item that corresponds to a specific section when clicked or scrolled into view. I've tried using CSS properties and Bootstrap, but I can't seem to get it working. Any assistance would be greatly appreciate ...

The boundary of embedded components

I am looking for CSS code that will allow me to arrange all elements with specific indents, such as placing the first element on the left side of the page, followed by an image with some indentation, and so on. <div class="container-fluid"> &l ...

How can I resolve the vertical adjustment issue of Bootstrap 5 input group on mobile devices?

My current issue involves using Bootstrap 5.2.3 to create an input group that displays a set of spans with the ".input-group-text" class alongside inputs with the ".form-control" class. While this setup works well on a computer screen, it does not adjust c ...

Using Bootstrap for Fixed Headers and Section Anchors

Despite my best efforts, I am struggling to resolve an issue with my fixed bootstrap navbar and internal links. I have experimented with various solutions, including using a JavaScript onscroll event listener and applying styles directly in the markup. How ...

Creating a div resizing function using only JavaScript is a fun and useful project to tackle

Seeking help to create a div resizer using only pure JavaScript as jQuery is restricted. The current functionality works, but breaks when the position of the slider-div is not set to absolute. Any solutions to fix this issue would be greatly appreciated. ...

What is the best way to arrange map items using justify-content-around for optimal display?

I'm currently iterating through products using the map function, but I'm having trouble getting the justify-content-around property to apply. I am working on a React project with Bootstrap 4 integrated. Below is the code snippet: {props.product ...

Elements are receiving CSS properties from other elements within the same component

I'm encountering an issue with my components: 1. I cannot seem to style html and body in signin.component.css for some reason. The workaround I found was using: encapsulation: ViewEncapsulation.None ==> This works perfectly However, when I switch ...

Using Vue to bind a class attribute with multiple Tailwind classes

I am attempting to associate an attribute and multiple tailwind classes with an HTML element. This is specifically for a tab menu where the goal is to dynamically display the title of the "active" tab and apply additional tailwind classes to modify the app ...

Improve the design of the email newsletter

Having some trouble coding a particular element in my email newsletter layout. This is the desired outcome: View Screenshot Here's what I currently have: View Screenshot Any idea what could be going wrong here? Check out the code snippet below: &l ...

What is the best way to position a div in the top right corner of my form using Bootstrap?

I have a form displaying some detailed text about elements in my application. Located outside this form is an "add new item" button that redirects the user to a new page for adding a new item. The current placement of this button is on the upper left corn ...

Is it possible to stack CSS pseudo-elements?

What is the most efficient way to create nested square-elements with minimal markup? I am aware that :after/:before cannot be stacked multiple times on the same element, so what would be the best way to achieve a structure like this? I am also facing chal ...

What is the best method for deleting an uploaded image from a box?

My code is quite lengthy, so I'll just showcase the JavaScript portion here. Here is a snippet of my JavaScript code: <script type="text/javascript"> let current = 0; for(let i = 0; i < 5; i++) { $('#thumbnail-view- ...

Learn how to use the CSS transform-scale() function to scale text independently from its container while maintaining proper alignment

I am currently working on adjusting font sizes to match another one, but I am facing an issue where the container's size is also being affected, resulting in misalignments. I have experimented with different display types (block, inline) and even trie ...

"Ascend beyond the constraints of fixed measurements with dynamic

My JQuery image fader has a width of 100% and height set to auto. I'm thrilled that it works perfectly on the iPhone as well. Now, I am facing a challenge while trying to make content "float" after my JQuery slider. The problem arises because I use ...

Resizing images in different web browsers: Chrome, IE, and Safari

I'm currently in the process of building a website that utilizes the jquery tabs api. Each tab on the site contains an image that I would like to resize dynamically as the browser window size changes. Here is an example of one of the tabs: <li st ...