【发布时间】:2016-03-14 02:01:55
【问题描述】:
我有一张图片和长文本,应该在图片上正确对齐。我给图像和文本赋予了 id,然后在 CSS 中我使用绝对位置、顶部和左侧的文本。一切正常,但是当我恢复浏览器时,文本不会停留在其原始位置。当我使用其他位置的文本时,它不会出现在图像上。
<img id="homeimg" src="images/1.jpg" alt="img" width="1280">
<p id="text">
In 2050, we are projected to have 9 billion on this planet. These people will eat and drink just like we do..
requiring a doubling of food production. But food and water security already are the largest challenges for a
thriving global population...and long text
</p>
css编码是
#text {
position: relative;
text-align: center;
width: 45em;
word-wrap: break-word;
font-size: 25px;
left: 150px;
top: 600px;
font-family: "Trebuchet MS";
z-index: 100;
}
#homeimg{
width:100%
}
【问题讨论】:
-
你能用我们能看到的图像做一个小提琴吗?
-
图像是内联对象。如果你想在图像上定位元素,他们必须有
position:absolute,W3school 有一个很好的例子。 w3schools.com/css/css_positioning.asp -
您是否尝试过使用您的图片作为 #text 元素的 css 背景图片?