我已经创建了一个自定义的html CSS代码,我想在wordpress中使用它代码在本地服务器上运行良好,但当我将其推送到自定义html块时,它就不一样了。我使用扁平主题我的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块中时溢出-y:滚动不适用于。scrolldiv我也尝试过使用overflow-y:scroll!重要但无济于事我相信有一些东西没有阻止我的代码
这就是我的代码在本地服务器上的样子
当我将此代码添加到wordpress 上的自定义块时,我的输出就是这样的
您确定您的内容足够长,可以滚动吗?我取了你的代码,将max-height: 20rem;
添加到.scroll-div
,然后它按照我想象的那样滚动。
作为参考,https://developer.mozilla.org/en-US/docs/Web/CSS/height
将高度定义为包含块的高度的百分比。
可能是因为包含块的定义不足,所以你70%的高度会产生硬边界,从而触发你想要的滚动效果。
在现场看到它可能更容易诊断。