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

Django模态窗口内容溢出容器问题技术求助

Django模态窗口内容溢出问题解决

问题根源与修复步骤

  1. 结构层级错误
    你的模态内容(Test Test...)直接放在了背景遮罩层(.modal_window_new_register)下,而非模态框容器(.new_register_modal)内部,导致内容不受模态框约束,直接溢出到外部。

  2. 缺少内部溢出控制
    模态框容器设置了固定高度95vh,但未处理内容超出时的滚动逻辑,需要添加垂直溢出滚动属性。

  3. 关闭按钮定位异常
    关闭按钮使用绝对定位,但父容器未设置相对定位,导致按钮以整个视口为基准定位,而非模态框本身。


修改后的代码

HTML代码

<div id="modal_window_new_register" class="modal_window_new_register" >
    <div class="new_register_modal">
        <button class="close" id="close">X</button>
        <!-- 所有模态内容必须放在这个容器内 -->
        Test Test Test Test Test
    </div>
</div>

CSS代码

/* Modal window */
.modal_window_new_register{
    width: 100vw;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    background-color: #00000080;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    overflow: auto;
}

.new_register_modal{
    width: 40%;
    min-width: 450px;
    height: 95vh;
    background-color: #ffff;
    padding: 20px;
    border-radius: 10px;
    /* 让内部绝对定位元素以当前容器为基准 */
    position: relative;
    /* 内容超出时垂直滚动 */
    overflow-y: auto;
}
.close{
    position: absolute;
    top: -15px;
    right: -15px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 0;
    background-color: #ffffff96;
    font-size: 20px; /* 补全单位 */
    cursor: pointer;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}
.modal_window_new_register.open_new_register_modal{
    display: flex;
}

内容的提问来源于stack exchange,提问作者Paulo Henrique A S A

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 14:42:54