程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了调整窗口大小时在引导程序中垂直和水平居中文本大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决调整窗口大小时在引导程序中垂直和水平居中文本?

开发过程中遇到调整窗口大小时在引导程序中垂直和水平居中文本的问题如何解决?下面主要结合日常开发的经验,给出你关于调整窗口大小时在引导程序中垂直和水平居中文本的解决方法建议,希望对你解决调整窗口大小时在引导程序中垂直和水平居中文本有所启发或帮助;

我希望有人能帮助我解决引导程序中一直存在的问题:根据窗口大小将主图像中的元素居中。

例如,这是我一直在处理的 LP 的屏幕截图,其中文本或多或少地显示在我笔记本电脑屏幕的中心。

Image_OK

但是当我将它移到更大的屏幕时,文本不会垂直居中(如下面的屏幕截图所示)

Image_not_OK

我认为这是由于我称之为 position: absoloute 的类,它有一个 position: absoloute。但是我尝试将其更改为 position: relative 并且它根本没有居中。

你能帮我找到正确的代码吗?

这是我在 HTML 中的代码:

<!--Main Hero Desktop-->
<div class="d-none d-lg-block desktopOnly">
    <div class="swiper-container swiper-desktop">
        <div class="swiper-wrapper">
            <a class="swiper-slIDe" href="#link#">
                <div class="row justify-content-center align-items-center text-center d-flex h-100">
                    <div class="col-12 col-md-6 h-50 position-absolute offer-text">
                        <div>
                            <p class="lead text-center pre-main-text">#main_preTitle#</p>
                            <h1 class="text-center main-Title">#main_Title_1#</h1>
                            <h1 class="text-center main-Title-price">#main_Title_price_1#</h1>
                            <p class="lead text-center vip-text">#main_vip#</p>
                            <p class="lead text-center sub-text">#main_subTitle_1#</p>
                            <span
                                class="btn text-center d-block d-xl-flex justify-content-xl-center align-items-xl-center newcta"
                                role="button">
                                #main_cta#
                            </span>
                        </div>
                    </div>
                </div>
                <img src="#cdn#D_Hero_img.jpg">
            </a>
            <a class="swiper-slIDe" href="#link#">
                <div class="row justify-content-center align-items-center text-center d-flex h-100">
                    <div class="col-12 col-md-6 h-50 position-absolute offer-text-2">
                        <div>
                            <h1 class="text-center main-Title-2">#main_Title_2#</h1>
                            <p class="lead text-center vip-text-2">#main_vip#</p>
                            <p class="lead text-center sub-text">#main_subTitle_2#</p>
                            <span
                                class="btn text-center d-block d-xl-flex justify-content-xl-center align-items-xl-center newcta-2"
                                role="button">
                                #main_cta#
                            </span>
                        </div>
                    </div>
                </div>
                <img src="#cdn#D_Hero_img_2.jpg">
            </a>
        </div>
        <!-- Add Arrows -->
        <div class="swiper-button-next swiper-desktop-next swiper-button-black"></div>
        <div class="swiper-button-prev swiper-desktop-prev swiper-button-black"></div>
    </div>
</div>

这是与之相关的CSS

.offer-text {
    top: 0.5vw;
}

.pre-main-text {
    text-transform: uppercase;
    Font-size: 23px;
    margin-bottom: 10px;
}

.main-Title {
    margin-bottom: -25px;
    Font-size: 3.9em;
    Font-family: Savoy-Roman;
    color: rgb(255,255,255);
}

.main-Title-price {
    Font-size: 10.4em;
    Font-family: Savoy-Roman;
    color: rgb(255,255);
    margin-bottom: -27px;
}

.main-Title-currency {
    Font-size: 0.4em;
    Font-family: Savoy-Roman;
    color: rgb(255,255);
    position: relative;
    top: -65px;
}

.vip-text {
    text-transform: uppercase;
    color: rgb(255,255);
    Font-size: 1.25em;
    letter-spacing: 3px;
    margin-bottom: -30px;
}

.sub-text {
    Font-family: canada-type-gibson;
    text-transform: uppercase;
    Font-size: 1.15em;
    margin-bottom: 2vw;
}

.newcta {
    background-color: var(--white);
    color: var(--black);
    padding: 20px 0px 20px 0px;
    wIDth: 215px;
    height: 55px;
    margin: -10px auto 0;
    Font-size: 16px;
    border-radius: 0rem;
}

.offer-text-2 {
    top: 8.5vw;
}

.main-Title-2 {
    margin-bottom: 10px;
    Font-size: 7.4em;
    Font-family: Savoy-Roman;
    color: rgb(255,255);
}

.vip-text-2 {
    text-transform: uppercase;
    color: rgb(255,255);
    Font-size: 1.25em;
    letter-spacing: 3px;
    margin-bottom: 3px;
}

.newcta-2 {
    background-color: var(--white);
    color: var(--black);
    padding: 20px 0px 20px 0px;
    wIDth: 215px;
    height: 55px;
    margin: 0px auto 0;
    Font-size: 16px;
    border-radius: 0rem;
}

.newcta:hover,.newcta-2:hover {
    background-color: var(--black);
    color: var(--white);
    border: 0px;
}

如果您看到我应该更改的任何其他内容以获得更清晰的代码,请告诉我,我愿意改进。

在此先谢谢你:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的调整窗口大小时在引导程序中垂直和水平居中文本全部内容,希望文章能够帮你解决调整窗口大小时在引导程序中垂直和水平居中文本所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: