gpt4 book ai didi

html -

文本左对齐,但我需要它在

类中的图像背景之上

转载 作者:太空宇宙 更新时间:2023-11-03 19:37:01 24 4
gpt4 key购买 nike

我正在做一场噩梦,试图让一小段文字位于我页面中心的图像上。我所管理的最接近的是文本框现在稍微居中。

我试图通过使用以图像为背景的 Div 类来完成此操作,并在 div 类“TEST”的段落内使用文本。我这样做是因为我稍后想在悬停时为它设置动画,但目前我只是想让文本位于图像之上!

我以为ma​​rgin: auto 0;会有所帮助,但它导致了更多问题,所以我将其删除并尝试使用 display: inline; 代替,这让我更接近了。现在我完全没有想法......

这是 p CSS:

p  {    
background: rgba(0,0,0,1);
background: -webkit-linear-gradient(bottom, rgba(0,0,0,1), rgba(0,0,0,.4));
background: -moz-linear-gradient(bottom, rgba(0,0,0,1), rgba(0,0,0,.4));
background: linear-gradient(bottom, rgba(0,0,0,1), rgba(0,0,0,.4));
padding: 2px;
line-height: 28px;
text-align: center;
position: absolute;
bottom: 0;
margin: 0;
display: inline;
}

这是 Div CSS 及其类:

div { 
height: 200px;
margin: 40px 0 0 0;
position: relative;
}

.TESTimage {
background-image: url("https://eccentric.productions/assets/roundlogo");
background-size: 100px;
background-repeat: no-repeat;
background-position: center;
height: 100px;
}

最后,HTML 的相关部分:

<body>
<div class="TEST">
<p>
Writing
</p>
</div>
</body>

非常感谢任何能帮助我的人,我已经使用 Stack Overflow 多年,但这是我第一次需要发布问题。你们做得很棒!

最佳答案

您必须删除 p 标签中的 position: absolute; 我删除 .test 类中的 background-position: center center; 以便于查看。这里是html代码

  <!DOCTYPE html >
<html >
<head>
<style type="text/css">
p {
background: rgba(0,0,0,1);
background: -webkit-linear-gradient(bottom, rgba(0,0,0,1), rgba(0,0,0,.4));
background: -moz-linear-gradient(bottom, rgba(0,0,0,1), rgba(0,0,0,.4));
background: linear-gradient(bottom, rgba(0,0,0,1), rgba(0,0,0,.4));
padding: 2px;
line-height: 28px;
text-align: center;

bottom: 0;
margin: 0;
display: inline;
}

div {
height: 200px;
margin: 40px 0 0 0;
position: relative;
}

.TEST {background-image: url("https://eccentric.productions/assets/roundlogo");
background-size: 100px;
background-repeat: no-repeat;

height: 100px;

}
</style>
</head>

<body>
<div class="TEST">
<p>
Writing
</p>
</div>
</body>
</html>

希望对你有帮助

关于html - <p> 文本左对齐,但我需要它在 <div> 类中的图像背景之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24935569/

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