Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I align a div to the top right corner of my <img>?

I have an image:

img {
  width: 250px;
  height: 250px;
  border: "1px solid black";
}
<img src='/image.jpg' alt='An image'>

Now what I want to do is align a div in such a way such that it’s in the top right corner of my img. Like this:
enter image description here

How do I do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Let me give an example:

To align a div to the top right corner of an img element, you can use CSS positioning.

.container {
  position: relative;
}

.content {
  position: absolute;
  top: 0;
  right: 0;
}
<div class="container">
  <img src="path/to/image.jpg">
  <div class="content">Content to be aligned</div>
</div>

Hope this will help you

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading