如何在图像上显示段落?(How can I display a paragraph over image?)

系统教程 行业动态 更新时间:2024-06-14 16:57:18
如何在图像上显示段落?(How can I display a paragraph over image?)

我有这个代码:

<ul class="lista_sus"> <li><img src="image/1.png" alt="Smiley face" height="250" width="250"></li> <li><img src="image/2.png" alt="Smiley face" height="250" width="250"></li> <li><img src="image/3.png" alt="Smiley face" height="250" width="250"></li> </ul>

我想在图像上显示一个段落。

我怎么解决这个问题?

你可以帮帮我吗?

提前致谢!

I have this code:

<ul class="lista_sus"> <li><img src="image/1.png" alt="Smiley face" height="250" width="250"></li> <li><img src="image/2.png" alt="Smiley face" height="250" width="250"></li> <li><img src="image/3.png" alt="Smiley face" height="250" width="250"></li> </ul>

I want to display a paragraph over image.

How can i solve this problem?

Could you help me?

Thanks in advance!

最满意答案

解决方案1:背景图像

您可以使用背景图像,在css中设置背景图像:

div{
  height:300px;
  width:300px;
  background:url(http://placekitten.com/g/300/300);
  } 
  
<div>This is some text</div> 
  
 


解决方案2:绝对定位

或者,您可以使用绝对定位,将段落“绝对”放在图像元素上:

ul {
  list-style: none;
}
li {
  position: relative;
}
li p {
  position: absolute;
  top: 0;
  left: 0;
  color:red;
} 
  
<ul class="lista_sus">

  <li>
    <img src="http://placekitten.com/g/300/200" alt="Smiley face" height="250" width="250">
    <p>This is a load of text</p>
  </li>

</ul> 
  
 

Solution 1: Background Image

You could use a background image for this, setting the background image in your css instead:

div{
  height:300px;
  width:300px;
  background:url(http://placekitten.com/g/300/300);
  } 
  
<div>This is some text</div> 
  
 


Solution 2: Absolute positioning

Or, you could use absolute positioning, placing the paragraph 'absolutely' over the image element:

ul {
  list-style: none;
}
li {
  position: relative;
}
li p {
  position: absolute;
  top: 0;
  left: 0;
  color:red;
} 
  
<ul class="lista_sus">

  <li>
    <img src="http://placekitten.com/g/300/200" alt="Smiley face" height="250" width="250">
    <p>This is a load of text</p>
  </li>

</ul> 
  
 

更多推荐

本文发布于:2023-04-12 20:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/f233c62affee2abf18f552d74b07bbab.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:段落   图像   如何在   image   paragraph

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!