gpt4 book ai didi

javascript - 将按钮固定在不断变化的 DIV 上

转载 作者:行者123 更新时间:2023-11-28 14:09:48 25 4
gpt4 key购买 nike

有什么方法可以将按钮对齐到 DIV 的中心。我能够使用 padding-top:2px 和 padding-bottom:2px 或使用 margin-top 和 margin 使其与不同的策略一起工作-底部。但问题来了,基本上它是一个移动的 DIV,即如果用户有更多信息,它可能会有所不同。例如,用户在输入文本字段中仅输入工作号码,它将仅显示唯一的工作电话number.But if the user enters work, home and additional number, it need to show all the information inputed, which will vary the size of the DIV. What happens is the div will increase in size and button stays at the top of the 顶部div。有什么方法可以让按钮固定在中心,即使 DIV 大小不同。可以在 CSS 中实现吗,或者我们需要使用 javascript 才能使其工作。

最佳答案

垂直对齐总是很棘手。

但是 demo 在哪里?使用 CSS 移动居中按钮并使用 jQuery 移动。

当它移动时,按钮保持在中心位置,因为尚未定义位置。

#outer {
text-align: center;
width: 200px;
background: #ddd;
height: 200px;
position: static;
display: table;
}
#inner {
line-height: 200px;
display: table-cell;
vetical-align: middle;
}

关于javascript - 将按钮固定在不断变化的 DIV 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9613052/

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