I want to achieve this structure using flex:
Which is responsive, on smaller screens it will look like this:
Please notice that the first div on mobile is the second one.
This is my code:
.card {
padding: 24px;
display: flex;
width: 400px;
background-color: #D9FBFF;
border-radius: 8px;
}
.right {
margin-left: auto;
display: flex;
flex-direction: column;
align-items: flex-end;
}
.div3 {
margin-top: auto;
}
.price {
display: flex;
align-items: baseline;
font-size: 20px;
font-weight: bold;
}
.unit {
margin-left: 6px;
font-size: 16px;
font-weight: normal;
}
.tag {
background: #D9DEEA;
border-radius: 7.5px;
height: 15px;
line-height: 15px;
text-align: center;
display: inline-block;
padding: 0 6px;
letter-spacing: 0.5px;
text-transform: uppercase;
font-size: 10px;
font-weight: bold;
}
.div3 {
display: flex;
align-items: flex-end;
flex-direction: column;
}
ul {
list-style: none;
padding: 0;
margin: 0;
margin-top: auto;
display: flex;
}
li:not(:last-child)::after {
content: "";
border-right: 1px solid #D9DEEA;
height: 14px;
margin: 0 12px;
}
h2 {
margin:0;
margin-bottom: 8px;
}
@media screen and (max-width: 800px) {
.card {
flex-direction: column;
}
.card > div {
width: 100%;
}
.right {
align-items: flex-start;
}
.div2 {
margin-bottom: 6px;
}
.div1 {
margin-bottom: 12px;
}
}
<article class="card">
<div class="div1">
<h2>This is a title</h2>
<div class="price">
<div>800</div>
<div class="unit">EUR</div>
</div>
</div>
<div class="right">
<div classs="div2">
<span class="tag">40% discount</span>
</div>
<div class="div3">
<ul>
<li>
<a href="#">LINK 1</a>
</li>
<li>
<a href="#">LINK 2</a>
</li>
</ul>
</div>
</div>
</article>
The only way I could achieve the first structure is by adding the second and third div inside a container div, but I don't know how to get around that to display the second div as the first one on smaller screens, I think all three divs should be in the same level, but, by doing that I don't know how can I achieve the first structure.
How can I solve this ?