Why doesn't work top attribute for <img>
, when the tag <img>
is sibling to <p>
, but if I delete tag <p>
, this works.
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="">
http://jsfiddle.net/9bxwxfe2/
Use a container div
set to position: relative;
and then add position: absolute;
to the img.
CSS:
html,body{
height: 100%;
}
img{
position: relative;
top: 40%;
float:left;
}
Use float:left; in the img class. This will solve the problem and image will be displayed in expected position(40% from the top of the screen).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With