gpt4 book ai didi

html -
    元素超出其各自的
    边界

转载 作者:太空宇宙 更新时间:2023-11-04 05:58:10 26 4
gpt4 key购买 nike

当我调整 div 大小时,div 的一个子元素越界。

我已经尝试向可调整大小和调整大小的 div 添加填充。

所有实际代码都包含在这里: https://github.com/LudwigVonChesterfield/Totally-Accurate-Political-Simulator

不能与上述代码分开工作的片段:

        <div id='div_player_chat' class='resizable' style='height: 200px; width: 400px; top: 60%; left: 60%'>
<div class='resizers'>
<div class='resizer top-left'></div>
<div class='resizer top-right'></div>
<div class='resizer bottom-left'></div>
<div class='resizer bottom-right'></div>

<div class="chat-wrapper">
<form id="player_chat-form">
<input id="player_chat" autocomplete="off" title="chat"/>
<button id="player_say">Say</button>
</form>
</div>
<ul id="player_events"></ul>
</div>
</div>

.resizable {
background: black;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}

.resizable .resizers {
width: 100%;
height: 100%;
border: 3px solid #4286f4;
box-sizing: border-box;
}

.resizers {
padding: 10px 10px 10px 10px;
}


.chat-wrapper {
padding: 10px 10px 10px 10px;
height: 35px;
background: dodgerblue;
}

.chat-wrapper form {
display: flex;
height: 30px;
}

.chat-wrapper form input {
font-size: 1.0rem;
margin: 0 10px 0 0;
padding: 0 5px;
flex-grow: 1;
}

.chat-wrapper form button {
width: 80px;
}

#player_events {
width: 100%;
height: 90%;
flex-grow: 1;
list-style: none;
margin: 0;
padding: 0;
border-bottom: 1px solid lightgrey;
overflow-y: scroll;
}

#player_events li {
padding: 10px 10px 10px 10px;
color: white;
}

我期待 <ul>相应地调整其大小 <div>永远不要越界。

然而结果是: https://cdn.discordapp.com/attachments/401030271417188355/613621706745053184/unknown.png

https://cdn.discordapp.com/attachments/489092762466254848/613618996977336320/2019-08-21_09-22-31.mp4

最佳答案

我建议你使用 flex。我已经从 ul 中删除了 height 规范,而是给它 flex-grow 属性,这将占用剩余空间。希望对你有帮助

.resizable {
background: black;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}

.resizable .resizers {
width: 100%;
height: 100%;
border: 3px solid #4286f4;
box-sizing: border-box;
}

.resizers {
padding: 10px 10px 10px 10px;
}

.d-flex {
display: flex;
flex-direction: column;
}

.chat-wrapper {
padding: 10px 10px 10px 10px;
height: 35px;
background: dodgerblue;
}

.chat-wrapper form {
display: flex;
height: 30px;
}

.chat-wrapper form input {
font-size: 1.0rem;
margin: 0 10px 0 0;
padding: 0 5px;
flex-grow: 1;
}

.chat-wrapper form button {
width: 80px;
}

#player_events {
width: 100%;
/*height: 90%;*/
flex-grow: 1;
list-style: none;
margin: 0;
padding: 0;
border-bottom: 1px solid lightgrey;
overflow-y: scroll;
}

#player_events li {
padding: 10px 10px 10px 10px;
color: white;
}
<div id='div_player_chat' class='resizable' style='height: 200px; width: 400px; top: 60%; left: 60%'>
<div class='resizers d-flex'>
<div class='resizer top-left'></div>
<div class='resizer top-right'></div>
<div class='resizer bottom-left'></div>
<div class='resizer bottom-right'></div>

<div class="chat-wrapper">
<form id="player_chat-form">
<input id="player_chat" autocomplete="off" title="chat" />
<button id="player_say">Say</button>
</form>
</div>
<ul id="player_events"></ul>
</div>
</div>

关于html - <ul> 元素超出其各自的 <div> 边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57585730/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com