I am beginner in css. I am trying to create a static website. I want to create a list of cards like below.
Things it should do:
- On hovering the card, it should get slightly larger like shown in the 2nd wireframe (But it should not affect the other cards) — This is where I am facing problem.
- Also list can be dragged to the either side/clicking on arrow/automatically in 10secs) to show other cards (if available)
- Also the list should be highly responsive. If the size of screen is below 1000px the cards can be shown in the column.
(Also please suggest a good animation for the list)
2
Answers
To make an element appear larger, apply a scale transform:
This should get you started. You’re creating a 2×2 grid, so the first step is to set up the HTML in the most minimalistic way possible. This is worthwhile, because a simple structure is easier to maintain.
We have a container (the grid parent) and four children. First we set up some basic rules for the parent.
The most important parts are the
grid-template-columns
andgrid-template-rows
, which establish the 2×2 grid. Anfr
is a unit of measurement used in CSS Grid. The rest of the CSS here is for setting up the demo (shown later).Now we need to deal with the arrows. Each arrow is associated with the box it’s in, yet appears outside each box. This makes these arrows great candidates for pseudo elements.
The first block sets up all the shared code between right and left arrows. The second and third blocks define the odd (top left/bottom left) and even (top right/bottom right box arrows.
If we put it all together, we arrive at something that you can start with and modify to your liking. I’ll leave the inner box styling as an exercise for you. Good luck!