How to position the image in html with inline css?

Viewed 515

I am trying to position an image somewhere in particular, so I need to use "top", "left" parameters instead of just "align: center". I used the below code, but it fails to move the image anywhere on the screen, it remains constant at a place.

<img src="./assets/button.png" alt="button" position: absolute; width: 346px; height: 40px; left: 1041px; top: 546px;>

Kindly help solve this. Thanks in advance!

3 Answers

Use something like this . Put all the css properties in the style

<img 
    src="./assets/button.png"
    alt="button"
    style="position:absolute; width:346px; height:40px; left:1041px; top:546px;"
>

Use like this

<img src="./assets/button.png" alt="button" style="position: absolute; width: 346px; height: 40px; left: 1041px; top: 546px;">

Also as you are positioning it to a specific position you have to be sure about which it is relative to.

Suppose you want it relative to a div. Make that div's style like this

<div style="position: relative;">
// other codes here
</div>

The problem is that you're missing the "style" attribute, otherwise your code should run properly.

Related