css 弹出窗口溢出溢出:汽车,我不明白为什么

vltsax25  于 2023-01-14  发布在  其他
关注(0)|答案(3)|浏览(122)

我知道这样的问题已经被问过几千次了,但是这个问题让我抓狂。我正在尝试创建一个简单的弹出窗口,父窗口的高度是设置好的,如果我设置标题栏的高度,它什么也不会改变。
希望有人能帮我这个忙,这样我今天就不用摔键盘了。
谢谢你。

html {
  height: 100vh;
}

#popup-window {
  position: absolute;
  ;
  height: 50%;
  width: 50%;
  background-color: #50ed77;
  border: 1px solid #3E3B3B;
  border-radius: 5px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 800px;
  z-index: 2;
  -webkit-box-shadow: 2px 2px #000;
  box-shadow: 2px 2px #000;
}

#popup-window-titlebar {
  background-color: #21522d;
  color: white;
  padding: 10px;
  font-weight: bold;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}

#popup-window-inner {
  margin: 5px;
  max-height: 100%;
  height: 100%;
}

#popup-window-list {
  margin: 5px;
  padding: 10px;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow-y: auto;
}

.window-close-btn {
  float: right;
  color: #fff;
  font-weight: bold;
  transition-duration: .5s;
}

.window-close-btn:hover {
  cursor: pointer;
  color: #ff115c;
}
<div id="popup-window">
  <div id="popup-window-titlebar">
    <b>Funny Title</b>
    <div class="window-close-btn">
      X
    </div>
  </div>
  <div id="popup-window-inner">
    <div id="popup-window-list">
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
    </div>
  </div>
</div>

想修复溢出。现在在谷歌上搜索了2个小时,尝试了不同的属性(位置,高度...)

xlpyo6sf

xlpyo6sf1#

我会让你的弹出窗口的方向列伸缩,然后你可以使内部伸缩增长(采取后的标题弹出剩余的高度)。
如果你把内部变量设为相对变量,你可以完全定位你的滚动div来填充内部变量,然后你的溢出就可以工作了:

html {
  height: 100vh;
}

#popup-window {
  position: absolute;
  height: 50%;
  width: 50%;
  background-color: #50ed77;
  border: 1px solid #3E3B3B;
  border-radius: 5px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 800px;
  z-index: 2;
  -webkit-box-shadow: 2px 2px #000;
  box-shadow: 2px 2px #000;
  display:flex;                 /* make this flex with a direction of column */
  flex-direction:column;
}

#popup-window-titlebar {
  background-color: #21522d;
  color: white;
  padding: 10px;
  font-weight: bold;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}

#popup-window-inner {
  margin: 5px;
  flex-grow: 1;          /* make this grow to fill remaining space and also relative */
  position:relative;
}

#popup-window-list {
  position:absolute;   /* absolutely position this to fill inner - 5px below replaces your margin */
  top:5px;
  left:5px;
  right:5px;
  bottom:5px;
  padding: 10px;
  overflow-y: auto;
}

.window-close-btn {
  float: right;
  color: #fff;
  font-weight: bold;
  transition-duration: .5s;
}

.window-close-btn:hover {
  cursor: pointer;
  color: #ff115c;
}
<div id="popup-window">
  <div id="popup-window-titlebar">
    <b>Funny Title</b>
    <div class="window-close-btn">
      X
    </div>
  </div>
  <div id="popup-window-inner">
    <div id="popup-window-list">
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
    </div>
  </div>
</div>
xzlaal3s

xzlaal3s2#

添加溢出并更改#popup-window的高度
更新样式

#popup-window-inner {
    margin: 5px;
    max-height: 100%;
    height: 76%;
    position: relative;
    overflow: hidden;
}
dluptydi

dluptydi3#

html {
  height: 100vh;
}

#popup-window {
  position: absolute;
  height: 50%;
  width: 50%;
  background-color: #50ed77;
  border: 1px solid #3E3B3B;
  border-radius: 5px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 800px;
  z-index: 2;
  -webkit-box-shadow: 2px 2px #000;
  box-shadow: 2px 2px #000;
  overflow-y: auto;
}

#popup-window-titlebar {
  background-color: #21522d;
  color: white;
  padding: 10px;
  font-weight: bold;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  position: sticky;
  top: 0
}

#popup-window-inner {
  margin: 5px;
  max-height: 100%;
  height: 100%;
}

#popup-window-list {
  margin: 5px;
  padding: 10px;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

.window-close-btn {
  float: right;
  color: #fff;
  font-weight: bold;
  transition-duration: .5s;
}

.window-close-btn:hover {
  cursor: pointer;
  color: #ff115c;
}
<div id="popup-window">
  <div id="popup-window-titlebar">
    <b>Funny Title</b>
    <div class="window-close-btn">
      X
    </div>
  </div>
  <div id="popup-window-inner">
    <div id="popup-window-list">
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
      <div>Entry</div>
    </div>
  </div>
</div>

相关问题