html - 无法让 div 粘在位置为 : absolute 的另一个 div 的底部

标签 html css

我正在尝试使用 position: absolutebottom:0; 让一个 div 粘在另一个 div 的底部; right:0,但它不起作用,因为 div 和底部之间仍然有一小段空间。

#weekly-product-container {
  margin-top: 91px;
  background: black;
  padding-top: 20px !important;
  width: 100vw;
  min-height: 500px;
  text-align: center;
  border-left: 1px solid #eee;
  display: flex;
  flex-direction: row;
  background-color: black;
  color: white;
  margin-top: 100px;
}
#triangle5 {
  width: 0px;
  height: 0px;
  border-left:  300px solid transparent;    
  border-bottom:  200px solid red;      
  border-bottom-right-radius: none; 
  bottom: 0;
  position: absolute;
  right: 0;
}
<div id="weekly-product-container">
  <div id="triangle5"></div>
</div>

最佳答案

您所要做的就是添加position: relative;到 weekly-product-container 并更改 bottom: 0; for triangle5:

#weekly-product-container {
    position: relative;
}

#triangle5 {
    position: absolute;
    bottom: 0;
}

这是一个例子:https://jsfiddle.net/cr29y1tc/30/

关于html - 无法让 div 粘在位置为 : absolute 的另一个 div 的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47348597/

相关文章:

javascript - Jquery - 使用窗口滚动时抖动滚动

html - 如何定位文本小部件?

html - 对于基于 Web 的数据输入屏幕的 WYSIWYG 编辑器的建议?

html - 当我使用 CSS3 按下按钮时,将文本输入设置为焦点

javascript - 填写表单时不会启用提交按钮

javascript - 使用 css 表插入行/列

html - 无法找到错误 "Warning: Task "uglify“未找到”的解决方案

javascript - 如何让 JavaScript 查询以 HTML 形式显示结果

html - 如何将图像显示为工具提示?

html - 为 Angular [Elements] 小部件隔离/范围所有 SCSS 样式的最简单方法是什么?