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>

flex CSS 属性

.container{
background:#ddd;
position: relative;
text-align:center;
width:100%;
height:300px;
display:flex;
align-items: center;
justify-content: center;

}
.text_bellow{
color:yellow;
position:relative;
font-size: 150px;  
text-align: center;

}
.text_over{
color:blue;
position:absolute;
width:100%;

}
<div class="container">
<div class="text_bellow">
<strong>DEALS</strong>
</div>
<div class="text_over">
<h3 class="first" style="">The Journey Began</h3>
<h1 class="second">EXPLORE THE BEST</h1></div>
</div>

最新更新