gpt4 book ai didi

html - 如何在没有绝对位置和 float 的情况下将 div 定位到容器的右端?

转载 作者:太空宇宙 更新时间:2023-11-04 01:48:35 25 4
gpt4 key购买 nike

是否可以在不使用绝对位置和 float 的情况下将 div 定位到容器的右侧?每当我使用 float:rightposition: absolute 时,容器都不知道 float 或定位元素的内容高度,这会导致布局问题。

我尝试为 float 或定位元素设置固定高度,然后将 padding-bottom 添加到 float 或定位元素的高度。

.container{
padding-bottom: 20px;
}

.container .float_right{
float: right;
height: 20px;
}

尽管没关系,但我正在寻找比这更好的解决方案。这里的任何人都可以告诉我是否有其他解决问题的方法吗?

最佳答案

只需将overflow: hidden; 添加到.container, read more here

.container{
padding-bottom: 20px;
overflow: hidden;
}

.container .float_right{
float: right;
height: 20px; /* no longer necessary */
}

我保留了 padding-topheight 样式,以便查看 overflow: hidden; 的效果。不需要固定高度。

codepen

关于html - 如何在没有绝对位置和 float 的情况下将 div 定位到容器的右端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43976912/

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