简体   繁体   English

调整三重容器垂直对齐中的文本位置

[英]Adjusting texts position inside a triple-containers vertical-align

I used a code that I found on Stack Overflow, to use vertical-align: middle using triple div from the following page: How can I vertically center a div element for all browsers using CSS?我使用了在 Stack Overflow 上找到的代码来使用vertical-align: middle使用来自以下页面的三重divHow can I vertically center a div element for all browsers using CSS?

I have 3 texts, 1 h1 and 2 h2 in my page that are all being put in the same container div, looks like the following:我的页面中有 3 个文本,1 个 h1 和 2 个 h2,它们都放在同一个容器 div 中,如下所示:

 .texts{ -webkit-text-stroke: 1px white; font-family: sans-serif; text-align: center; margin-left: auto; margin-right: auto; } #h1landing{ font-size: 4em; animation: fading 3s forwards; }.outertexts{ display: table; position: fixed; top: 0; left: 0; height: 100%; width: 100%; }.innertexts{ display: table-cell; vertical-align: middle; } #h2{ animation: introThis 6s forwards; font-size: 2em; } #h2v2{ font-size: 2em; animation: introAwaits 9s forwards; }.h2{ margin-top: 0px; } @keyframes introThis{ 0% {opacity: 0%;} 50% {opacity: 0%;} 65%{opacity: 100%; transform: translateY(0px)} 70%{animation-delay: 5s; transform: translateY(0px)} 100%{transform: translateY(-150px)} } @keyframes introAwaits{ 0% {animation-delay: 5s; opacity: 0%;} 60% {opacity: 0%} 75%{opacity: 100%; transform: translateY(0px)} 80%{animation-delay: 5s; transform: translateY(0px)} 100%{transform: translateY(-100px)} } @keyframes fading{ 0% {opacity: 0%; transform: translateX(80%);} 50% {opacity: 100%; transform: translateX(0);} 75% {transform: translateY(0px); animation-delay: 10s} 100% {transform: translateY(-200px)} }
 <div class="outertexts"> <div class="innertexts"> <div class="texts"> <h1 id="h1landing"> Header 1 </h1> <div class="h2"> <h2 id="h2"> Header 2-1 </h2> <h2 id="h2v2"> Header 2-2 </h2> </div> </div> </div>

In the inserted Snippet, you could see that between Header 1, Header 2-1 and Header 2-2 there are big gaps, and I would like to close these gaps (Between the 2 h2s).在插入的代码段中,您可以看到标题 1、标题 2-1 和标题 2-2 之间存在很大差距,我想缩小这些差距(在 2 h2s 之间)。 I tried a few things but none of them are working and honestly, my brain is neither.我尝试了一些东西,但都没有用,老实说,我的大脑都没有用。 I hope anyone could fix this;我希望有人能解决这个问题; Im very sorry for the length of this question.对于这个问题的长度,我感到非常抱歉。

Thank you very much in advance!非常感谢您!

You can decrease the gap between 2 h2s by,你可以减少 2 h2s 之间的差距,

h2 {
   margin-top: 0;
   margin-bottom: 0;
}

you defined the class .h2 and make margin zero but that cannot affect inside of the div.您定义了类.h2并使边距为零,但这不会影响 div 的内部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM