'vertical align heading with flex container
In this excercise i expect to put header h2 on the same vertical line with the first card from left. each card is a flex item width width 160px in a flex container gap 44px. I can set margin left for h2 to make it align with the card but that wont make h2 responsive. please someone show me how to fix this
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
text-transform: capitalize;
font-size: 16px;
font-family: "Source Sans Pro", sans-serif;
}
h2 {
font-family: "Montserrat", sans-serif;
font-weight: 200;
font-size: 36px;
text-transform: uppercase;
margin-bottom: 55px;
letter-spacing: 1px;
}
.flex, .product .cards .card .square .new, .product .cards .card .square .sale, .product .cards {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
.product {
display: flex;
flex-direction: column;
margin-top: 140px;
}
.product h2 {
margin-bottom: 70px;
}
.product .cards {
gap: 44px;
flex-wrap: wrap;
}
.product .cards .card {
width: 160px;
border: 1px solid #dfe5e8;
}
.product .cards .card:hover {
cursor: pointer;
}
.product .cards .card .square {
height: 200px;
background: #f0f3f2;
position: relative;
}
.product .cards .card .square .badget {
font-family: "Montserrat", sans-serif;
text-transform: uppercase;
font-weight: 700;
}
.product .cards .card .square .sale {
width: 64px;
height: 64px;
border-radius: 50%;
font-size: 14px;
color: white;
background: #00bcd4;
position: absolute;
left: 120px;
top: 20px;
z-index: 2;
}
.product .cards .card .square .new {
width: 53px;
height: 53px;
border-radius: 50%;
font-size: 14px;
color: white;
background: #393d50;
position: absolute;
left: 123px;
bottom: 78px;
z-index: 1;
}
.product .cards .card .content {
padding: 27px 0;
line-height: 30px;
text-align: center;
}
.product .cards .card .content .name {
padding: 0;
color: #b4bdc3;
}
.product .cards .card .content .price {
color: #00bcd4;
}
@media only screen and (max-width: 600px) {
.ship_total .ship select,
.ship_total .ship input {
width: 100%;
}
.ship_total .ship .zip {
margin-left: 0;
}
.ship_total .ship button {
width: 100%;
}
.ship_total .total table {
width: 100%;
}
.product .cards {
flex-direction: column;
}
}
/*# sourceMappingURL=page.css.map */
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;700&family=Source+Sans+Pro:wght@300;400&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="/css/page.css" />
</head>
<body>
<div class="container">
<div class="product">
<h2>you may be interested in</h2>
<div class="cards">
<div class="card">
<div class="square"></div>
<div class="content">
<p class="name">denim classy shorts</p>
<p class="price">$35.00-$89.99</p>
</div>
</div>
<div class="card">
<div class="square">
<div class="badget">
<div class="sale">sale!</div>
<div class="new">new</div>
</div>
</div>
<div class="content">
<p class="name">golden heels</p>
<p class="price">$89.99</p>
</div>
</div>
<div class="card">
<div class="square"></div>
<div class="content">
<p class="name">black impression</p>
<p class="price">$259.99</p>
</div>
</div>
<div class="card">
<div class="square"></div>
<div class="content">
<p class="name">denim classy shorts</p>
<p class="price">$35.00-$89.99</p>
</div>
</div>
<div class="card">
<div class="square"></div>
<div class="content">
<p class="name">golden heels</p>
<p class="price">$89.99</p>
</div>
</div>
<div class="card">
<div class="square"></div>
<div class="content">
<p class="name">black impression</p>
<p class="price">$259.99</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|