html - 如何使按钮和复选框固定在 DIV 的底部

标签 html css

如何将我的按钮和复选框固定在我的 div 的底部。我也能够让我的滚动功能正常工作。我的问题是按钮和复选框没有固定在底部。

因此,当我用文本填充 div 时,文本会溢出按钮和复选框,但我怎样才能使文本包含在可滚动的内容中而不溢出按钮和复选框?

#chk {
  float: left
}

.btn {
  float: right
}
<div style="height:40%; overflow: scroll;" class="panel" id="panel">

 <!--inner part of the div which contains the text (scrollable is applied here) -->

  <input id="chk" type="checkbox" /> <!-- should be on the left bottom of the div -->

  <button type="submit" class="btn">Button</button> <!--should be on the right bottom of the div (opposite the checkbox)-->

</div>

最佳答案

请注意,我在两个交互元素周围添加了一个包装器 div。 如果您在标记中有任何限制不允许您将它们包装在容器中,请告诉我,我们会在这种情况下找到另一种解决方案。

#panel {
  position:relative;
  padding-bottom: 2rem;
}
    
.panel-bottom {
  position: absolute;
  bottom: 0;
  width: 95%; /* to be resized as it suits you */
  background-color: white;
  height: 2rem;
  padding: .5rem;
}
#chk {
  position: absolute;
  left: 0;
}
.btn {
  position: absolute;
  right: 0;
}
<div style="height:40%; overflow: scroll;" class="panel" id="panel">

inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)inner part of the div which contains the text (scrollable is applied here)


  <div class="panel-bottom">
    <input id="chk" type="checkbox" />
    <button type="submit" class="btn">Button</button>
  </div>

</div>

关于html - 如何使按钮和复选框固定在 DIV 的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47364929/

相关文章:

html - 为什么在 css 中从下到上获取菜单列表?

javascript - 关闭浏览器窗口/选项卡时如何删除 localStorage 项目?

css - Angularjs:为菜单中的每个页面定义不同的CSS

javascript - 使用 CSS 设置数据表样式以删除边框并更改数据单元格高度?

html - 无法减小 Chrome 中可调整大小的文本区域的大小

html - -webkit-flex 无法在 Android 上正确显示

html - 旋转文本的 CSS 定位和对齐

javascript - jquery 在加载之前从页面中删除图像

javascript - 按Ctrl键时出现Gif