search

Home  >  Q&A  >  body text

Relatively positioned top not working as expected

Why the top attribute of does not work when the label is the same level as

, but This works if I remove the tag

.


html,
body {
  height: 100%;
}

img {
  position: relative;
  top: 40%;
}
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus delectus accusantium nulla eveniet aperiam, quo odit qui voluptas. Illo vel sed ex dolores illum eum architecto a libero atque. Voluptatibus.</p>
<img src="http://lorempixel.com/400/200/" alt="">


P粉566048790P粉566048790500 days ago673

reply all(1)I'll reply

  • P粉521013123

    P粉5210131232023-10-30 11:16:49

    http://jsfiddle.net/9bxwxfe2/

    Use a container div set to position:relative; and then add position:absolute; to the img.

    reply
    0
  • Cancelreply