为什么我的 CSS 相对定位不起作用?
Why is my CSS relative positioning not working?
我在使用相对/绝对等定位移动任何 div 时遇到问题。任何帮助将不胜感激,干杯。
代码:
<div id="game"><img src="gta-game.jpg" height="100" width="70" alt="gta"/></div></li>
<div id="gamename">Grand Theft Auto V</div>
<div id="rating">9/10<div>
<div id="system">PS4</div>
CSS:
#game{
height: 100px;
width: 70px;
display: relative;
left: 50px;
}
#gamename{
display: relative;
right: 50px;
}
#rating{
display: relative;
right: 100px;
}
#system{
display: relative;
right: 200px;
}
正确的 属性 是 position: relative
,而不是 display: relative
。
您正在使用 display
。您应该使用 position
。试试这个:
#game{
height: 100px;
width: 70px;
position: relative;
left: 50px;
}
#gamename{
position: relative;
right: 50px;
}
#rating{
position: relative;
right: 100px;
}
#system{
position: relative;
right: 200px;
}
我在使用相对/绝对等定位移动任何 div 时遇到问题。任何帮助将不胜感激,干杯。
代码:
<div id="game"><img src="gta-game.jpg" height="100" width="70" alt="gta"/></div></li>
<div id="gamename">Grand Theft Auto V</div>
<div id="rating">9/10<div>
<div id="system">PS4</div>
CSS:
#game{
height: 100px;
width: 70px;
display: relative;
left: 50px;
}
#gamename{
display: relative;
right: 50px;
}
#rating{
display: relative;
right: 100px;
}
#system{
display: relative;
right: 200px;
}
正确的 属性 是 position: relative
,而不是 display: relative
。
您正在使用 display
。您应该使用 position
。试试这个:
#game{
height: 100px;
width: 70px;
position: relative;
left: 50px;
}
#gamename{
position: relative;
right: 50px;
}
#rating{
position: relative;
right: 100px;
}
#system{
position: relative;
right: 200px;
}