gpt4 book ai didi

html - 将文本放在图像上,无论它是否存在

转载 作者:太空宇宙 更新时间:2023-11-04 04:36:54 25 4
gpt4 key购买 nike

如果数据库中存在文本,我想将文本放在图像上;如果不存在,我想将文本放在图像上。

我面临的问题是,如果有图像,文本就会出现在图像下方,如果图像不存在,文本就会出现在正确的位置,如所附图片所述。代码如下:

<div class="category">
<img src="home.php?cat={$mc.categoryid}"/>
<div class="title">
<h2>Some text</h2>
</div>
</div>

我想按照以下方式做一些事情:

<style>
.category{
width: 400px;
height: 400px
}

.title {
position: relative;
top: 3px;
left: 0;
width: 100%;
height: 50px;
}
</style>

http://i.stack.imgur.com/HSSeN.png

最佳答案

给你的容器 category position relative。然后把absoluteposition.titleposition:absolute 从正常的内容流中取出分配给它的任何内容。容器上的 position:relative; 会将 position:absolute 元素保留在该空间内。但是您仍然可以将其移动到您想要的位置。因此,如果您想让 .title 出现在右下角,请应用 right:0bottom:0

等样式>

Fiddle

关于html - 将文本放在图像上,无论它是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16227469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com