suchen

Heim  >  Fragen und Antworten  >  Hauptteil

Relativ positioniertes Oberteil funktioniert nicht wie erwartet

Warum das oberste Attribut von nicht funktioniert, wenn das Tag auf der gleichen Ebene wie ist 的 top 属性不起作用,当标签

是同级时,但是如果我删除标签

, aber wenn ich das Tag

entferne und das funktioniert.


1

2

3

4

5

6

7

8

9

html,

body {

  height: 100%;

}

 

img {

  position: relative;

  top: 40%;

}

1

2

<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粉566048790480 Tage vor652

Antworte allen(1)Ich werde antworten

  • P粉521013123

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

    http://jsfiddle.net/9bxwxfe2/

    使用设置为 position:relative; 的容器 div,然后将 position:absolute; 添加到 img。

    Antwort
    0
  • StornierenAntwort