I am learning CSS/HTML5. I want to put in a grid of 2 rows x 2 columns these 4 cards, I want make this page responsive the four cards distribuited in the screen when open in mobile :
Here is my html code of frotaDan.html :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Frota Daniel</title>
<link href="css/main.css" rel="stylesheet" />
</head>
<body>
<div class="reja">
<section>
<div class="card">
<h2>Free Willy</h2>
<div class="card-image boat1"></div>
<p>Lancha de 38 pés convertida para pescaria em alto mar.
</p>
<a href="#">Agenda</a>
</div>
<div class="card">
<h2>Yu</h2>
<div class="card-image boat2"></div>
<p>Barco robaleiro de 7 metros, com Painel na popa,
projetado para até 4 pescadores + guia.
</p>
<a href="#">Agenda</a>
</div>
<div class="card">
<h2>Xalana</h2>
<div class="card-image boat3"></div>
<p>Barco robaleiro de 7 metros, com Painel na popa,
projetado para até 4 pescadores + guia.
</p>
<a href="#">Agenda</a>
</div>
<div class="card">
<h2>Victory</h2>
<div class="card-image boat4"></div>
<p>26 pés ,painel e controle central,
com espaço para pesca em volta do barco todo,
</p>
<a href="#">Agenda</a>
</div>
</section>
</div>
</body>
And this is the main.css:
*{ box-sizing:border-box; padding: 0; margin:0; }
body { background: rgb(27, 27, 27); }
.container { display:flex; justify-content: center; }
.card { background: white; width: 500px; height: 600px; margin: 10px;
border-radius: 15px; align-items: center; text-align: center; display:
inline-block; }
.card:hover { background-color: black; color: white; cursor:pointer;
transform : scale(1.03); transition : all in ease;
}
.card-image { background-color: aqua; height: 150px; margin-bottom: 15px;
background-size: cover; }
.boat1 { background-image: url('../img/FreeWilly/FreeWi3mini.jpg'); }
.boat2 { background-image: url('../img/Xu/X4Mini.jpg'); }
.boat3 { background-image: url('../img/xalana.jpeg'); }
.boat4 { background-image: url('../img/Victorymini.jpg'); }
.card a { background-color: black; color:white; padding: 15px 20px;
display:block; text-align: center; margin: 20px 50px; }
.reja { display: grid;}
I have tryed many propierties in CSS to order this cards.
thanks in advance
Alejandro
2
Answers
I used display:flex. try it out and see if you like it.
You have a css rule for
.container
(defining the flex container), but there is no element in your HTML code which actually has that class…So – in the HTML code – add
class="container"
as an attribute to thesection
element, and then – in CSS – movealign-items: center;
from the rule for.card
(= flex items) to the.container
rule (flex container).