html - 宽度 100 % 超出父级
问题描述
我正在尝试创建一个div#firstdiv
. 在那个 div 里面我还有其他div#otherdiv
的,它们的宽度是 % of #firstdiv
。此外,这个其他 div 有一个特定的边距,不应该受到另一个的影响,#otherdiv
但我的问题是当我这样做时position :absolute; widht:100%
#otherdiv 超出了 #firstdiv。让我们看一个例子。我有 :
<div style=" width: 500px; border: 2px solid red; height: 150px; >
<div style="width: 100%; position: absolute; border: 1px solid blue; >here<div>
</div>
我有以下结果:
我希望蓝色的 div 在红色的里面。如果我这样做,它会起作用如果position absolute
我有另一个#otherdiv
剩余边距取决于已经存在的东西,我不想要那个。
我改变了任何东西:我正在使用引导程序,我的这两个潜水在里面
<div class="container-fluid container-first"><div class="container">
解决方案
像这样添加position relative
到父级
<div style=" width: 500px; border: 2px solid red; height: 150px; position: relative" >
<div style="width: 100%; position: absolute; border: 1px solid blue;">here</div>
</div>
推荐阅读
- objective-c - 只有在我的一个项目中,我根本无法使用 Xcode 断点,lldb 崩溃并始终使用相同的日志。有没有办法调试这个问题?
- python - 从其他函数和模块调用字典
- java - 如何使用 BufferedReader + StringTokenizer 实现 hasNext() 方法?
- javascript - 如何使用菜单按钮显示相应的元素数据类别?
- php - 如何在 PHP 中以每秒 100 次的方式批量进行 api 调用
- css - 为非 ASP .NET Core 应用寻找 SASS/SCSS/Less 库
- raku - 以逗号更改并行监视器大小
- python - 从没有括号[] python的函数返回一个numpy数组
- python - 将列表转换为 np 数组
- multiprocessing - Dask DataFrame 未使用 scheduler='processes' 启动任务