You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何div无法置于轮播图下方?前端布局问题求助

轮播图下方段落错位的修复方案

你的问题源于三个细节错误,修复后就能让段落正常显示在轮播图下方:


问题分析

  1. 类名大小写不匹配:HTML中轮播容器是class="Slider",但CSS里写的是.slider,导致容器样式完全没生效
  2. 轮播容器高度塌陷:.myslider默认display: none,父容器没有内容撑高,后面的packcontainer会自动上移填补空白
  3. 动画语法错误:@keyframes fade里的opacity: 0,4是标点错误,应该用英文点号0.4

修复步骤

  1. 统一类名大小写:把HTML里的<div class="Slider">改成<div class="slider">,和CSS选择器保持一致
  2. 撑开轮播容器高度:给第一个轮播项添加style="display: block;",让页面加载时默认显示一张图,容器就能被内容撑高
  3. 修正动画语法:把opacity: 0,4改为opacity: 0.4

修改后的完整代码

HTML代码

<nav class="nav">
    <div class="container">
        <div class="logo">
            <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="#FFD60A" class="bi bi-camera-fill" viewBox="0 0 16 16">
                <path d="M10.5 8.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0z" />
                <path d="M2 4a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2h-1.172a2 2 0 0 1-1.414-.586l-.828-.828A2 2 0 0 0 9.172 2H6.828a2 2 0 0 0-1.414.586l-.828.828A2 2 0 0 1 3.172 4H2zm.5 2a.5.5 0 1 1 0-1 .5.5 0 0 1 0 1zm9 2.5a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0z" />
            </svg>
            <h1 class="name">Zon Photography</h1>
        </div>
        <div class="menu">
            <a href="" class="is-active">HOME</a>
            <a href="#PACKAGES">PACKAGES</a>
            <a href="">PHOTOS</a>
            <a href="">ABOUT</a>
            <a href="">CONTACT US</a>
        </div>
        <button class="humberger">
            <span></span>
            <span></span>
            <span></span>
        </button>
    </div>
</nav>
<div class="slider">
    <!-- 默认显示第一张轮播图,撑开容器高度 -->
    <div class="myslider fade" style="display: block;">
        <img id="imgslid" src="/Images/1.jpg" style="width:100%">
    </div>
    <div class="myslider fade">
        <img id="imgslid" src="/Images/2.jpg" style="width:100%">
    </div>
    <div class="myslider fade">
        <img id="imgslid" src="/Images/3.jpg" style="width:100%">
    </div>
    <div class="myslider fade">
        <img id="imgslid" src="/Images/4.jpg" style="width:100%">
    </div>
    <div class="myslider fade">
        <img id="imgslid" src="/Images/5.jpg" style="width:100%">
    </div>
</div>
<div class="packcontainer">
    <p> My paragraph goes here</p>
</div>

CSS代码

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Raleway', sans-serif;
}

.container{
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

nav{
    position: absolute;
    top:0;
    left: 0;
    right: 0;
    z-index: 99;
    padding: 16px 32px;
}
/* Slide Show Container */
.slider{
    position: relative;
    background-color: #003566;
}
/* Hide the images by default*/
.myslider{
    max-height: 255px;
    display: none;
}
/* Fading animation */
.fade {
    animation-name: fade;
    animation-duration: 0.5s;
}
  
@keyframes fade {
    from {opacity: 0.4} /* 修正标点错误 */
    to {opacity: 1}
}
/* LOGO */ 
svg{
    margin-top: 20px;
}
/* ZON PHOTOGRAPHY */
.name{
    display: none;
    float: right;
    color: #FFC300;
    padding: 10px;
    transition: 0.4s;
    font-size: 35px;
    font-family: 'Pacifico', cursive;
}

/* Humberger Container */ 
.humberger{
    display: block;
    position: relative;
    z-index: 1;
    user-select: none;
    appearance: none;
    border: none;
    outline: none;
    background: none;
    cursor: pointer;
}
/* Humberger Lines */
.humberger span{
    display: block;
    width: 33px;
    height: 4px;
    margin-bottom: 5px;
    position: relative;
    background-color: #FFC300 ;
    border-radius: 6px;
    z-index: 1;
    transform-origin: 0 0;
    transition: 0.4s;
}
/* Humberger Transofrmation */
.humberger:hover span:nth-child(2){
    transform: translateX(10px);
    background-color: #003566;
}
.humberger.is-active span:nth-child(1){
    transform: translate(0px, -2px) rotate(45deg);
}
.humberger.is-active span:nth-child(3){
    transform: translate(-3px, 3px) rotate(-45deg);
}
.humberger.is-active span:nth-child(2){
    opacity: 0;
    transform: translateX(15px);
}

.humberger.is-active:hover span{
    background-color: #0862b8;
}
/* NAV MENU LIST */
.menu{
    display: none;
    flex: auto;
    justify-content:center;
    align-items: center;
    margin: 0;
}
.menu a{
    color: white;
    text-decoration: none;
    padding: 15px;
    font-weight: bold;
    font-size: 18px;
    transition: 0.4s;  
}

.menu a:hover{
    color:#FFC300;
}
/* NAV MENU TRANSFORMATION */
@media (min-width: 768px){
    .humberger{
        display: none;
    }
    .menu{
        display: flex;
    }
    .name{
        display: flex;
    }
    .slider img{
        width: 100%
    }   
}

内容的提问来源于stack exchange,提问作者abdelmouiz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 20:15:35