【问题标题】:CSS overflow-y is not working in WordpressCSS 溢出-y 在 Wordpress 中不起作用
【发布时间】:2022-01-03 16:52:59
【问题描述】:

我创建了一个我想在 wordpress 中使用的自定义 html CSS 代码 该代码在我的本地服务器上运行良好,但是当我将其推送到自定义 html 块时,它的工作方式就不一样了。 我使用flatsome主题 我的html代码是

    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="style.css">
        <!-- <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link href="https://fonts.googleapis.com/css2?family=Work+Sans:wght@100;200;300;400;500;600&display=swap" rel="stylesheet"> -->
    </head>
    <body>
        <div class="empty-space"></div>
        <h3 class="title">Limited only by imagination</h3>
        <div class="main-down-div">
            <div class="main-div">
                <div class="scroll-div">
                    <div class="content-container">
                        <div class="content">
                            <h4 class="sub-title">Taste The Freshness Of Herbs</h4>
                            <div class="content-images">
                                <img src="Lemon-Balm.png">
                                <img src="Lemon-Balm.png">
                                <img src="Lemon-Balm.png">
                                <img src="Lemon-Balm.png">
                            </div>
                        </div>
                    </div>
                    <div class="content-container">
                        <div class="content">
                            <h4 class="sub-title">Grow Your Own Edibles</h4>
                            <div class="content-images">
                                <img src="Spinach.png">
                                <img src="Strawberries.png">
                                <img src="Sunflower.png">
                                <img src="Thyme.png">
                            </div>
                        </div>
                    </div>
                    <div class="content-container">
                        <div class="content">
                            <h4 class="sub-title">Eat Healthy Microgreens</h4>
                            <div class="content-images">
                                <img src="Spinach.png">
                                <img src="Strawberries.png">
                                <img src="Sunflower.png">
                                <img src="Thyme.png">
                            </div>
                        </div>
                    </div>
                    <div class="content-container">
                        <div class="content">
                            <h4 class="sub-title">Liven Up Your Space</h4>
                            <div class="content-images">
                                <img src="Spinach.png">
                                <img src="Strawberries.png">
                                <img src="Sunflower.png">
                                <img src="Thyme.png">
                            </div>
                        </div>
                    </div> 
                </div>
            </div>
        </div>
    </body>
</html>

CSS 代码

body{
    font-family: 'Work Sans', sans-serif;
    background-color: rgb(237, 237, 237);
}
.main-div{
    background-color: rgb(237, 237, 237);
    position: relative;
}
.title{
    text-align: center;
}
.sub-title{
    text-align: center;
    font-size: 1.6vw;
    font-weight: 500;
    color: #404040;
}
.content-container{
    width: 80%;
    margin: auto;
}
.content{
    margin: 0 0 10%;
}
.content-images{
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
}
.content-images img{
    width: 15%;
}
.scroll-div::-webkit-scrollbar {
    display: none;
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */    
}
.main-div::after{
    content: '';
    height: 125px;
    top: 0;
    right: 0;
    left: 0;
    position: absolute;
    background: linear-gradient(to bottom, rgba(237, 237, 237, 1) 0%, rgba(237, 237, 237, 0) 100%);
}
.main-down-div{
    position: relative;
}
.main-down-div::after{
    content: '';
    height: 100px;
    bottom: 0;
    right: 0;
    left: 0;
    position: absolute;
    background: linear-gradient(to top, rgba(237, 237, 237, 1) 0%, rgba(237, 237, 237, 0) 100%);
}
.scroll-div{
    overflow-y: scroll;
    height: 70%;
    position: relative;
    padding-top: 3%;
}

.empty-space{
    height: 100px;
}
@media only screen and (max-width: 600px) {
    .scroll-div{
        padding-top: 10%;
        padding-bottom: 20%;
    }
    .content-images img{
        width: 50%;
    }
    .title{
        font-size: 8vw;
    }
    .sub-title{
        text-align: center;
        font-size: 6vw;
    }
    .scroll-div{
        height: 75%;
    }
    .empty-space{
        height: 0px;
    }
}

当我将此代码放在 wordpress 上的自定义 html 块中时 overflow-y: scroll; 不适用于 .scroll-div 我也尝试过使用 overflow-y: scroll !important; 但它没有帮助 我相信有些东西没有阻止我的代码

this is how my code looks on my local server

this is how my output is when I add this code to a custom block on wordpress

【问题讨论】:

    标签: html wordpress


    【解决方案1】:

    您确定您的内容足够长,可以滚动吗?我拿走了你的代码并将 max-height: 20rem; 添加到 .scroll-div 并按照我想象的那样滚动。

    供参考,https://developer.mozilla.org/en-US/docs/Web/CSS/height

    将高度定义为包含块高度的百分比。

    可能包含块定义不充分,以至于您的 70% 高度会创建硬边界,从而触发您正在寻找的滚动效果。

    在实时网站上看到它可能更容易诊断。

    【讨论】:

    • 是的,当我添加尺寸增加的图像时,我确信内容足够长,就像我说它在我的本地服务器上工作正常一样。它只是在我的 wordpress 上不起作用
    • 很抱歉,本地和生产之间的脱节听起来令人沮丧。如果有在 WP 中查看它的链接,我会很感兴趣。很抱歉,我无法提供更多帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 1970-01-01
    • 2016-05-29
    • 2017-05-18
    • 2017-11-27
    • 2016-04-22
    相关资源
    最近更新 更多