So, I was doing this Frontend Mentor challenge (at https://www.frontendmentor.io/challenges/notifications-page-DqK5QAmKbC) while I had run into this problem – I couldn’t align the "Chess" image in the "Kimberly Smith" notification to the right.
Here is all the code I have written related to the notification:
The HTML:
<div class="notification">
<div class="notification__container">
<img src="assetsimagesavatar-kimberly-smith.webp" class="image" />
<div class="notification-formatting">
<div class="align-right">
<div><strong>Kimberly Smith</strong> commented on your picture
<br /><time>1 week ago</time>
</div>
<div class="img-container"><img src="assets/images/image-chess.webp" alt="Chess" class="image chess"></div>
</div>
</div>
</div>
</div>
The CSS:
img,
picture,
svg,
video {
display: block;
max-width: 100%;
}
.notification {
background-color: #f6fafd;
display: flex;
align-items: center;
}
.notification__container {
display: flex;
align-items: center;
}
.image {
display: flex;
align-items: center;
width: 50px;
margin-right: 5px;
}
.notification_image--main-message-content {
display: flex;
}
.align-right {
display: flex;
}
Here is the Output
Here is the Expected Output
Here are the solutions I have tried:
display: block;
margin-left: auto;
float: right;
text-align: right;
display: flex;
justify-content: right;
Here is the live website: https://prismatic-capybara-4ba8da.netlify.app/
Here is the GitHub Repository for deeper reference: https://github.com/vishalscodes/frontendmentor-notifications-page
Thank You.
2
Answers
Base on your code you can set to
.align-right {justify-content: space-between; width: 100%; display: flex;}
and set 100% width to all parents divs you can see code bellow
It’s possible to massively simplify your markup as follows:
notification
. This is a flex box so items will try to fit side by side on one line. As the user’s image, the main text and the ‘chess’ image are all on one line we don’t need to add any more divs to this. We can just insert them directly, especially as you’ve made allimg
elements as blocks (this is always a good move imho).notification-formatting
is used to isolate the text so that the text and time stack on top of each other. As this is a flex item, this will try to shrink to fit the content.chess
class as that’s already a block level element so to get that to move to the right I’ve added analign-right
class. That simply has an inline-margin ofauto 0
. This is a fairly standard way of moving elements to the right of the page.Some good resources here:
Any questions just drop me a comment and I’ll try help out.