This is a piece that is in the sidebar I’m building. I move the image to the far right of the screen with style="text-align: right;"
. In the same div, above the image, there is also a red bar that I would like aligned exactly like the image. But I can’t align the red bar as well.
The alignment and position of the image is right, alright, now I would like to align that red bar as well as the image.
I need this:
(both blue bar and red image, both must be aligned on the extreme right side of the screen. As said, the red image is already ok, the blue one is not)
How can i get this?
.bar {
background-color: blue;
font-size: 11px;
color: white;
padding-left: 2px;
width: auto;
}
<!doctype html>
<html lang="en">
<head>
<!-- Boostrap Files -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="col-md-4 col-lg-4 d-flex flex-column">
<div id="pub" style="text-align: right;">
<div style="text-align: center" class="bar">My Bar</div>
<img src="https://i.postimg.cc/d32tkpdw/ddddddddfdfdfdf.png" alt="aaa">
</div>
</div>
</body>
</html>
2
Answers
If you know the width of the image, you can set the blue div’s width as the same value and set the
margin-left: auto
which automatically adds margin as needed:Since you’re using Bootstrap and already have the bar and image in a flex container, just use the appropriate Bootstrap class. Replace
flex-column
withjustify-content-end