html - HTML如何将文本覆盖在另一个文本上并垂直居中
问题描述
我是编码新手,我正在尝试将一个文本框放在另一个文本框之上。可以在以下链接中看到我要实现的目标的说明
https://i.stack.imgur.com/Oe7Dn.png
我找到了一些代码,它把文本放在另一个上面
<div style="background:;position: relative;text-align:center;width:100%;">
<div style="color:yellow;position:relative;font-size: 50px; text-align: center;"><strong>THIS IS PARAGRAPH THIS IS PARAGRAPH
<div style="color:blue;position:absolute;top:0;width:100%;">hello</div>
</div>
但是我无法根据需要更改它。有什么建议吗?我觉得这应该不难,但由于我的知识目前有限,我没有看到解决方案。
非常感谢您的帮助。
解决方案
我只是将 CSS ::after与背景文本的内容和绝对定位一起使用。
尝试以下并调整值以适合您。也许这也会清理 HTML。
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;800&display=swap');
*{
padding: 0px;
margin: 0px;
}
section {
display: flex;
height: 100vh;
justify-content: center;
align-items: center;
}
main {
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
main::after {
content: "DEALS";
position: absolute; /* This will break text out of flow */
z-index:-1; /* This will place text right at the back */
font-size: 120px;
opacity: 0.2;
font-family: 'Open Sans', sans-serif;
font-weight: 800;
}
.first{
font-family: 'Open Sans', sans-serif;
font-weight: 800;
color: blue;
}
.second{
font-size: 60px;
font-family: 'Open Sans', sans-serif;
font-weight: 600;
line-height: 45px;
}
<section>
<main>
<h3 class="first" style="">The Journey Began</h3>
<h1 class="second">EXPLORE THE BEST</h1>
</main>
</section>
推荐阅读
- tensorflow - 为什么在 Tensorflow 教程中将 sqrt(dim) 与 Transformer 的编码输入相乘?
- javascript - 拥有“ ?${new Date().getTime()} ”如何更新 JS 中的图像
- swiftui - ForEach 不能使用分支
- java - Android Studio,从 Java 库运行 main,弃用,从命令行运行
- javascript - 再次单击后如何删除JS中的类?
- android - android 9文件上传(MultipartUploadRequest)错误
- hive - Hive 中字符串比较中 % 与 * 之间的差异
- html - 使 div 垂直居中导致它稍微水平偏离中心
- reactjs - 如何编写数据数组,即在控制台部分中显示到反应 js 中的 excel 表
- javascript - Axios:先前的响应数据被分配给变量