Hi,
I’m working on a project, and at the stage where I’m trying to get everything responsive.
I started the project with mobile-first, and working on the desktop. I’m making changes as I go along.
However, I’ve noticed for my container-detail, the content does not take up the full width of the container when the screen is big, which leaves a lot of empty space.
I’ve been trying different heights such as max-height / height to no avail.
Can anyone please advise where I went wrong?
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,700&family=Montserrat:wght@500;700&display=swap" rel="stylesheet">
<title>Frontend Mentor | Product preview card component</title>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<div class="container">
<picture>
<source media="(max-width: 1200px)" srcset="images/image-product-mobile.jpg">
<source media="(min-width: 1200px)" srcset="images/image-product-desktop.jpg">
<img src="images/image-product-mobile.jpg" alt="Bottle of Chanel Perfume">
</picture>
<div class="container-detail">
<p class="perfume-text">Perfume</p>
<h1>Gabrielle Essence Eau De Parfum</h1>
<p class="about">A floral, solar and voluptuous interpretation composed by Olivier Polge,
Perfumer-Creator for the House of CHANEL.</p>
<div class="price-container">
<span class="sale">$149.99</span>
<span class="original">$169.99</span>
</div>
<button>
Add to Cart
</button>
</div>
</div>
</body>
</html>
CSS:
:root {
--clr-dk-cyan: hsl(158, 36%, 37%);
--clr-cream: hsl(30, 38%, 92%);
--clr-dk-blue: hsl(212, 21%, 14%);
--clr-gray-blue: hsl(228, 12%, 48%);
--clr-white: hsl(0, 0%, 100%);
--ff-primary: 'Montserrat', sans-serif;
--ff-secondary: 'Fraunces', serif;
}
/* CSS RESET */
*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
body {
background-color: var(--clr-cream);
line-height: 1.5;
-webkit-font-smoothing: antialised;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
img, picture {
display: block;
width: 100%;
}
p, h1, h2, h3, h4, h5, h6 {
overflow-wrap: break-word;
}
/* STYLES: MOBILE-FIRST */
.container {
display: flex;
flex-direction: column;
background-color: var(--clr-white);
border-radius: 10px;
overflow: hidden;
}
.perfume-text {
color: var(--clr-gray-blue);
font-family: var(--ff-primary);
font-size: 0.75rem;
letter-spacing: 0.3rem;
text-transform: uppercase;
}
h1 {
font-family: var(--ff-secondary);
line-height: 1;
}
.about {
color: var(--clr-gray-blue);
font-family: var(--ff-primary);
font-size: 0.8rem;
line-height: 1.7;
}
.container-detail {
gap: 10px;
padding: 10px;
margin: 15px;
display: flex;
flex-direction: column;
}
.price-container {
display: flex;
align-items: center;
gap: 15px;
}
.sale {
color: var(--clr-dk-cyan);
font-family: var(--ff-secondary);
font-size: 2rem;
}
.original {
color: var(--clr-gray-blue);
font-family: var(--ff-primary);
font-size: 0.8rem;
text-decoration: line-through;
}
button {
background-color: var(--clr-dk-cyan);
border: none;
border-radius: 5px;
color: var(--clr-white);
font-family: var(--ff-primary);
font-size: 0.8rem;
font-weight: 700;
padding: 15px;
}
button::before {
content: url(images/icon-cart.svg);
padding: 5px;
}
/* DESKTOP STYLES */
@media (min-width: 1200px) {
.container {
display: grid;
grid-template-columns: repeat(2, 1fr);
max-width: 60%;
border: 2px solid blue;
}
.container-detail {
border: 1px solid red;
gap: 30px;
}
img {
height: 100%;
object-fit: cover;
}
/*
Thanks!