It’s not much, but I’ll offer all my fg for a solution
So I'm stuck on something at the moment and wanting to see if someone can help me
Currently, I have 4 cards of trucks with the name of the truck, the image, and a short description. The goal is, when someone clicks on one of these truck cards, it will update the information + picture on the info-holder section.
My current solution is, everything is hardcoded into the HTML which I don't like at all. I was wondering if this could be done using a json file + javascript to display the information dynamically when a user clicks a card. Right now I would fill in the json data manually.
Info contains:
- An Image of the truck (url)
- Size information
- Suitable for
- More information
Currently I'm unsure how I would even approach this, so any help would be great
The markup is very rough just for demonstration purposes.
Code
<div class="info-holder">
<img src="https://www.tatamotors.com/wp-content/uploads/2018/01/19065024/prima.jpg" alt="">
<div class="size info-card">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tincidunt sem nisl, a tristique turpis suscipit vitae. Quisque euismod, dui sit amet semper tempus, mauris elit varius diam</p>
</div>
<div class="weight info-card">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tincidunt sem nisl, a tristique turpis suscipit vitae. Quisque euismod, dui sit amet semper tempus, mauris elit varius diam</p>
</div>
<div class="suitable-for info-card">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tincidunt sem nisl, a tristique turpis suscipit vitae. Quisque euismod, dui sit amet semper tempus, mauris elit varius diam</p>
</div>
<div class="info info-card">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tincidunt sem nisl, a tristique turpis suscipit vitae. Quisque euismod, dui sit amet semper tempus, mauris elit varius diam</p>
</div>
</div>
<div class="cards">
<div class="card">
<img src="https://www.tatamotors.com/wp-content/uploads/2018/01/19065024/prima.jpg" alt="">
<h2>Truck one</h2>
<p>Truck description</p>
</div>
<div class="card">
<img src="https://www.tatamotors.com/wp-content/uploads/2018/01/19065024/prima.jpg" alt="">
<h2>Truck one</h2>
<p>Truck description</p>
</div>
<div class="card">
<img src="https://www.tatamotors.com/wp-content/uploads/2018/01/19065024/prima.jpg" alt="">
<h2>Truck one</h2>
<p>Truck description</p>
</div>
<div class="card">
<img src="https://www.tatamotors.com/wp-content/uploads/2018/01/19065024/prima.jpg" alt="">
<h2>Truck one</h2>
<p>Truck description</p>
</div>
</div>
Code
* {
box-sizing: border-box;
}
.info-holder {
width: 100%;
border: 1px solid green;
padding: 40px;
height: 500px;
display: relative;
}
.info-holder img {
display: block;
margin: 0 auto;
}
.cards {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-gap: 16px;
margin-top: 40px;
}
.card {
border: 1px solid green;
padding: 20px;
}
.card img {
width: 100%
}
.info-card {
width: 300px;
position: absolute;
border: 1px dashed red;
}
.info-card:nth-of-type(1) {
top: 10%;
}
.info-card:nth-of-type(2) {
bottom: 40%;
}
.info-card:nth-of-type(3) {
top: 10%;
right: 4%;
}
.info-card:nth-of-type(4) {
bottom: 40%;
right: 4%;
}
Here is a screenshot of the current page to give you an idea
https://imgur.com/a/Bckee6wThis post was edited by Strickland on Nov 26 2019 11:06pm