gpt4 book ai didi

css - float div 并将其保持在基线

转载 作者:行者123 更新时间:2023-11-28 10:18:26 25 4
gpt4 key购买 nike

我正在为一个元素开发一个聊天模块,除了 css 之外一切正常。我有一个聊天元素的全局容器,这个 div 有固定的位置。我里面有两个 div,一个用于聊天窗口,一个用于联系人列表,聊天窗口和联系人列表都向右浮动,可以通过单击标题“最小化”(这会隐藏主体,只留下标题可见)。问题是,如果我只最小化其中一个 div,它会保留在顶部,与另一个 div 的高度相同(见图)。

这是我得到的:

the container in the right remains at the top of the div

这就是我想要的:

enter image description here

相关代码:

<body>
<!--boring code-->

<div class="chat_container">
<div class="contactos show">
<div class="titulo">contactos</div>
<div class="container">
<div class="contacto online" id="contacto_3">juan an orozco</div>
</div>
</div>
<div class="chat_wdow_container">
<div class="chat_wdow " id="chat_wdow_3">
<div class="title_area">juan an orozco</div>
<div class="container">
<div class="msg_area"></div>
<input type="text" name="msg">
</div>
</div>
</div>
</div>
</body>

和CSS

div.chat_container
{
position: fixed;
bottom: 0px;
left: 0px;
right: 0px;
border: 1px dashed gold;
}

div.chat_container > div
{
float: right;
}

div.chat_container div.contactos div.titulo
{
text-align: center;
}


div.chat_container div.contactos
{
min-width: 150px;
background: dimgrey;
padding: 5px;
border-radius: 10px 10px 0 0px;
}

div.chat_container div.contactos div.container
{
display: none;
min-height: 145px;
padding: 10px;
}
div.chat_container div.contactos.show div.container
{
display: block;
}

div.chat_container div.chat_wdow
{
margin: 0 5px;
min-width: 190px;
background: dimgrey;
padding: 5px;
border-radius: 10px 10px 0 0px;
float: left;
}

div.chat_container div.chat_wdow div.title_area
{
text-align: center;
}

div.chat_container div.chat_wdow div.container div.msg_area
{
background-color: white;
height: 120px;
padding: 10px;
}

div.chat_container div.chat_wdow div.container
{
display: none;
}

div.chat_container div.chat_wdow.show div.container
{
display: block;
}

.chat_wdow input[type="text"]
{
width: 186px;
}

为了折叠窗口,我通过 mootools 切换类 .show。当缺少此类时,窗口的容器区域有 display:none,当它被应用时,它有 display:block

到目前为止我尝试了什么:

  • 将固定父级设置为高度 0 并且溢出可见
  • 将内部容器设置为相对定位,将子容器设置为绝对定位
  • 使用清除和溢出技巧
  • 将边距更改为自动值
  • 更改内部容器和子项的垂直尺寸和最小高度
  • 将显示更改为内联和内联 block
  • 将聊天容器更改为绝对容器,将内部容器更改为相对容器

我已经在谷歌和 SO 上搜索了一段时间,但我只找到了我已经尝试过的选项,我也查看了 facebook 的聊天 css,但我找不到任何可以帮助我的东西,所以我正在寻找降低折叠的 div 的新想法。

最佳答案

一种解决方案是改用 display:inline-block 或 display:inline,然后设置 vertical-align:bottom。

例如:http://jsbin.com/uhubeh/1/edit

但是,如果您知道两者的宽度,您也可以只使用绝对定位。

关于css - float div 并将其保持在基线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16248458/

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