What is the best way to display cards next to each other on desktop and mobile devices while maximizing available space?

In the world of React components, there exists a card representation within a grid view that adapts based on available screen space;

function EngineerCard(engineer: EngineerDetail) {
  return (
    <div className='engineerCard'>
      <div>
        <img src={engineer.avatar}/>
      </div>
      <div>
        <h4>{engineer.name}</h4>
        <h5>{engineer.role}</h5>
        <p>{engineer.summary}</p>
      </div>
      <div>
        <button>f</button>
        <button>in</button>
        <button>g</button>
      </div>
    </div>
  );
}

Utilizing CSS in this manner;

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

.gallery {
  display: flex;
  flex-wrap: wrap;
}

.engineerCard {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  background-color: #2F2c34;
  width: 250px;
  height: 400px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  text-align: center;
  margin: 30px;
  padding-top: 20px;
  padding-left: 20px;
  padding-right: 20px;
  border-radius: 10px;
}

.engineerCard img {
  margin-left: auto;
  margin-right: auto;
  width: 128px;
  height: 128px;
  border-radius: 50%;
}

.engineerCard button {
  width: 20px;
  height: 20px;
  border: none;
  background-color: #fff;
  margin-left: 10px;
}

.engineerCard button:hover {
  cursor: pointer;
}

.engineerCard:last-child {
  background-color: #dfe432;
  height: 30px;
  width: 250px;
}

This results in the following appearance;

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

  1. What causes the yellow footer of the card to be misaligned while its buttons are perfectly positioned?

  2. Why is the background of the second card white instead of the specified color?

  3. Why doesn't the CSS property justify-content: space-around; take effect on the second card?

Answer №1

The concept of :last-child in CSS, as explained by MDN, refers to the final element within a set of sibling elements. To target the ultimate div within a group, use the selector .engineerCard div:last-child

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

The variable 'xxx' is not defined in this context

I am attempting to incorporate a dark theme into ngx-charts, and I'm relatively new to using less. Here is the code snippet: My IDE is showing an error message "Cannot find variable 'color-bg-darker'" which leads to compilation failure. Err ...

What is the best way to trigger a jQuery function once a form has been successfully submitted?

Is there a way to execute a jQuery function AFTER a form has been submitted? I am familiar with calling a function ON submit, but I specifically need it to run after the form data has been posted and stored in the database using PHP. In my website projec ...

Simple method to toggle between elements using jQuery

After creating a script using jQuery to show/hide content when tabs are clicked (which also changes the color of the clicked tab), everything is functioning smoothly. However, I believe there may be a more efficient way to switch between content that allow ...

Show inline-block elements within a div that has a variable width, allowing for horizontal scrolling

Currently, my layout is as follows: https://jsfiddle.net/0r6cdwht/2/ Is there a way to enable horizontal scrolling when the items displayed inside the div overflow? I've done some research and came across a solution that suggested using white-spac ...

Assistance with Collision Detection in HTML5 Canvas using JavaScript

Attempting to create a platformer game using HTML5 and the canvas feature. I managed to implement collision detection with rectangles, but encountered issues when adding multiple rectangles. I have a function that adds new objects to an array with attribut ...

The parent and child elements both attempted to define the background color, but neither was successful in applying it

Here is the html code snippet: body { font-family: Arial, Helvetica, sans-serif; } header { background-color: rgb(93, 43, 78); background-image: -webkit-linear-gradient(right, rgb(93, 43, 78 ...

Dealing with errors in AJAX divs

Utilizing an AJAX-based script known as AJAXTwits, I've been able to seamlessly load multiple Twitter timelines for a sports team into a designated div. The standout features of this script include its ability to combine various timelines into a singl ...

The JavaScript slideshow fails to display an image during one rotation

The slideshow displays a sequence of images from pic1.jpg to pic8.jpg, followed by a 4-second pause with no image, and then repeats starting again at pic1.jpg. I am looking to have it loop back to pic1.jpg immediately after displaying pic8.jpg. Below is t ...

Customizing the Sorting of Bars in Apex Charts: A Step-by-Step Guide

I have implemented a horizontal Bar Chart using React Apex-Charts, and it currently looks like this: I would like to change the default sort order from Ascending to Descending, so that the bar with the highest value appears at the top and the smallest v ...

Adding the 'None' option to a select menu using Material UI in a React application can

I am currently working on implementing Material UI React Storybook. To avoid hardcoding select options, I have mapped them out. However, I am struggling to add a "None" option similar to the Material UI select component. When "None" is selected, nothing sh ...

Do you have any recommendations for a creative CSS method to achieve a full-screen background image?

After searching online and experimenting with different methods, I have yet to discover a solution that suits my needs. My goal is to have the background image on my website centered, filling the entire browser screen, while also being compatible with resp ...

Strategies for patiently waiting for an object to appear before loading the HTML

After logging into my service, I download data from a REST API, and based on that data, I display certain tabs. However, I am experiencing issues with loading the HTML content once the data has been retrieved. The ngif directive at the beginning of the H ...

Will other users be affected if a shared CPU droplet crashes?

'I wasn't able to find the answer through internet searches, so I apologize in advance if this question has been asked before... When using Artillery to test a DigitalOcean shared CPU droplet, will intentionally increasing the load affect other ...

Position an element to the right inside its parent container with varying width in Internet Explorer 7 or earlier

I am trying to align a button to the right edge of a table inside a container-div that has no set width. The goal is to have the button float on the right side of the table, lining up with its right edge. While my current approach works in most browsers, i ...

Selecting the perfect default font using font-display: fallback

When I use a particular font and find that its loading time is too high, I want to set a default font. So I experimented with the following code: font-display: fallback; It seems to be working fine (although I haven't checked compatibilities yet), ...

Guide on navigating from a React page to an Express page

Hi, I'm trying to figure out how to redirect a React page to an Express page in order to send an email if a user forgets their password. I attempted to use Router, but it redirected me to 'localhost:3000/forgot_password' instead of 'loc ...

Handling Click and Mouse Events with React [react-sortable-hoc, material-ui, react-virtualized]

I have come across an interesting example that I would like to share with you. Check out this live working example on Stackblitz When the delete button on the red bin icon is pressed, the onClick event handler does not get triggered (sorting happens inst ...

Creating effective href anchors within an iframe using the `srcdoc` attribute

While loading some HTML content in an iframe using the srcdoc attribute, I encountered an issue where following anchor tag links inside the iframe caused the entire page to load within the iframe instead of scrolling to the linked id. You can see a demons ...

Having trouble navigating through multiple layers of nested array data in react js

I need help understanding how to efficiently map multiple nested arrays of data in a React component and then display them in a table. The table should present the following details from each collection: title, location, description, and keywords. Below ...

Using Javascript to Conceal Button for Unauthenticated Users

Our website is currently running on an outdated e-commerce CMS platform, which limits my options due to my beginner level skills in JavaScript and jQuery. One specific issue we are facing is the need to hide Prices and Add to Cart buttons for users who ar ...