鱼C论坛

 找回密码
 立即注册
查看: 448|回复: 3

[已解决]为何浮动后原位置还被占有位置

[复制链接]
发表于 2024-7-5 13:01:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
其中#end为父元素,其余都为子元素。
  1.    

  2.         #end {
  3.             background-color: lightseagreen;
  4.             height: 3000px;
  5.             padding-left: 10px;
  6.             column-count:5;
  7.             column-rule: 2px dashed #ccc;
  8.             column-gap: 5px;
  9.             position:relative;
  10.         }
  11.     .news {
  12.             width: 240px;
  13.             height:auto;
  14.             padding: 10px;
  15.             border: 1px solid #ccc;
  16.             border-radius: 5px;
  17.             box-shadow: 0 0 5px #ccc;
  18.             margin: 10px;
  19.             margin-left:20px;
  20.             break-inside: avoid;
  21.             position:relative;
  22.         }

  23.             .news img {
  24.                 position:relative;
  25.                 width: 240px;
  26.                 display: block;
  27.                 height: auto;
  28.             }

  29.         .endwords {
  30.             position: relative;
  31.             bottom: 110px;
  32.             background-color: wheat;
  33.             width: 240px;
  34.             opacity: 0;
  35.             color: black;
  36.             height: 110px;
  37.             text-align:center;
  38.             line-height:110px;
  39.             float:left;
  40.         }
复制代码
最佳答案
2024-7-5 20:00:41
在浮动元素之后添加一个清除浮动的元素:
html
<div style="clear: both;"></div>
使用伪元素清除浮动:
css
#end::after {  
    content: "";  
    display: table;  
    clear: both;  
}
这两种方法都可以帮助父元素正确地调整其高度,以适应浮动子元素。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-7-5 20:00:41 | 显示全部楼层    本楼为最佳答案   
在浮动元素之后添加一个清除浮动的元素:
html
<div style="clear: both;"></div>
使用伪元素清除浮动:
css
#end::after {  
    content: "";  
    display: table;  
    clear: both;  
}
这两种方法都可以帮助父元素正确地调整其高度,以适应浮动子元素。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-7-8 08:41:13 | 显示全部楼层
某一个“天” 发表于 2024-7-5 20:00
在浮动元素之后添加一个清除浮动的元素:
html

清除了浮动效果的,结果还是占有了位置
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-7-8 08:47:44 | 显示全部楼层
某一个“天” 发表于 2024-7-5 20:00
在浮动元素之后添加一个清除浮动的元素:
html

按照这个思路我已经解决了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-13 21:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表