Search code examples
htmlcssalignmentright-align

I can't align an image to the right


I tried everything but could not align the image to the right.

I tried to search all around the internet, and worked on this problem for several days. I used text-align: right; and margin: right; and many more. I expected that it would align to the right, but instead it didn't and resulted in it getting bigger and smaller. Can you help me?


Solution

  • I guess the easiest way is to use flexbox.

    <body>
    <div style="display: flex; justify-content: end;">
        <img src="..." alt="...">
    </div>
    </body>
    

    And you have to make sure the parent div-element has a width of 100%. You can check that by using the inspector of your browser.

    (Firefox: cmd/strg + shift + c, Safari/Chrome: cmd/strg + shift + i, or just use right-click and choose 'inspect' on the bottom)