I am working on creating a simple card design using HTML and CSS. Here’s the basic design:
So far this is my code:
.map-drawer-item {
border-radius: 0.25rem;
background: #EEE;
color: #797979;
font-family: Roboto;
font-size: 0.875rem;
font-weight: 700;
display: flex;
flex-direction: column;
align-items: flex-start;
position: relative;
padding-right: 1rem;
max-width: 300px;
}
.map-drawer-item-header {
display: flex;
align-items: center;
}
.map-drawer-item-status {
margin: 0 1rem;
}
.map-drawer-item-header h5 {
font-size: 1rem;
margin-right: 0.5rem;
}
.map-drawer-item-sub {
font-size: 0.875rem;
font-weight: 500;
color: #797979;
margin-left: 2.6rem;
margin-top: -1rem;
padding-bottom: 1rem;
}
.map-drawer-item-icon-more {
position: absolute;
right: 1rem;
transform: translateY(-50%);
font-size: 1.2rem;
}
<div class="map-drawer-item">
<div class="map-drawer-item-header">
<span class="map-drawer-item-status">
<img src="empty.svg" alt="" srcset="">
</span>
<h5>AT-TP279 - SOme name</h5>
</div>
<div class="map-drawer-item-sub">
<span>1692 km / 07:50</span>
</div>
<span class="map-drawer-item-icon-more">
<img src="more-icon.svg" alt="" srcset="">
</span>
</div>
This code isn’t functioning as expected. For instance, when there is a long title, it doesn’t work well. Is using Flexbox the right approach, or should I consider an alternative solution?
Thank you all for your assistance.
I want to maintain a consistent and flexible card layout, even when dealing with long titles. Furthermore, I would like to keep the ‘more’ icon in a fixed position
2
Answers
please check if this is good for you. you just have to play with the margin-top for those icons to stay aligned with the text. or you can just remove the margin then it will align on top.
To create a consistent and flexible card layout that handles long titles and keeps the "more" icon in a fixed position, you can make a few adjustments to your HTML and CSS code. Here’s a modified version of your code:
Here are the key changes made:
Added
flex-wrap: wrap;
to.map-drawer-item-header
to allow the header content to wrap to the next line if it’s too long.Added
flex-grow: 1;
to.map-drawer-item-header h5
to allow the title to grow and take up available space.Added
overflow: hidden;
,text-overflow: ellipsis;
, andwhite-space: nowrap;
to.map-drawer-item-header h5
to handle long titles by hiding overflow text and showing ellipsis for long titles.These changes should help you maintain a consistent and flexible card layout, even when dealing with long titles. The "more" icon remains in a fixed position.