首页 > 解决方案 > 将按钮放在父 div 的右下角,而不是页面

问题描述

我不知道如何在父 div 的右下角放置一个按钮。我找到的解决方案适用于页面的角落,这不是我需要的。你能帮忙吗?

.tile {
  background-color: grey;
  width: 200px;
  height: 200px;
}

.my_img {
  position: absolute;
  right: 0;
  bottom: 0;
}
<div class="tile">
  <p>some text</p>
  <button class="my_img">My Button</button>
</div>

标签: htmlcss

解决方案


只需设置position:relative为类图块

.tile {
  background-color: grey;
  width: 200px;
  height: 200px;
  position:relative;
}

.my_img {
  position: absolute;
  right: 0;
  bottom: 0;
}
<div class="tile">
  <p>some text</p>
  <button class="my_img">My Button</button>
</div>


推荐阅读