I am new to in field of web developing. I am learning from internet free resources and courses, so there are no one to solve my subtle problems. I got a task to arrange card deck using HTML and CSS to achieve this type of arrangement
So, I write HTML alike.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>My First page</title>
</head>
<body>
<div class="card">
<div class="card2"></div>
<div class="card3"></div>
<div class="card4"></div>
</div>
</body>
</html>
Now in .css file I want to put an card image to all child <div>
and want to resize images. How can I do that? I tried this CSS below.
.card {
width: 200px;
height: 280px;
background-image: url(https://i.pinimg.com/originals/10/80/a4/1080a4bd1a33cec92019fab5efb3995d.png);
background-size: 200px 280px;
position: relative;
z-index: 1;
}
.card2 {
background-image: url(https://i.pinimg.com/originals/10/80/a4/1080a4bd1a33cec92019fab5efb3995d.png);
background-size: 200px 280px;
position: absolute;
top: 60pxpx;
left: 50px;
z-index: 2;
}
.card3 {
background-image: url(https://i.pinimg.com/originals/10/80/a4/1080a4bd1a33cec92019fab5efb3995d.png);
width: 200px height:280px;
position: absolute;
top: 100px;
left: 80px;
z-index: 3;
}
.card4 {
background-image: url(https://i.pinimg.com/originals/10/80/a4/1080a4bd1a33cec92019fab5efb3995d.png);
width: 200px height:280px;
position: absolute;
top: 150px;
left: 150px;
z-index: 4;
}
3
Answers
You have multiple typo in your code as:
top: 60pxpx;
I dont think you want to want this way, maybe you just forget to close the first div in time, pay more attention for this kind of errors.
And answer for your question
Here is the sort way to achieve this using position property and CSS variable.
One approach is below, with explanatory comments to try to show how it works:
JS Fiddle demo.
References:
aspect-ratio
.inline-szie
.position
.translate
.var()
.NodeList.prototype.forEach()
.