javascript - 如何使用 html 和 CSS 在一个 div 中添加复选框列表

标签 javascript html css

我需要使用 HTML 和 CSS 在一个 div 中显示一些复选框列表。我在下面解释我的代码。

<div class="col-md-6">
   <div class="input-group bmargindiv1 col-md-12">
        <span class="input-group-addon ndrftextwidth text-right" style="width:180px">Multiple Business Name :</span>
                //list of business names with check box         
    </div>
</div>

span 之后,我需要显示带有复选框的多个标签,如果在 6 之后还有更多,列表将滚动。请帮助我。

最佳答案

要实现滚动行为,请将复选框插入 .container div,为其指定固定的 height 并设置 overflow-y: scroll;。如果内容变得大于容器本身,这会使容器垂直滚动。请参阅 MDN more information about overflow-y .

.container {
  height: 120px;
  overflow-y: scroll;
}
<div class="col-md-6">
  <div class="input-group bmargindiv1 col-md-12">
    <span class="input-group-addon ndrftextwidth text-right" style="width:180px">Multiple Business Name :</span>
    <div class="container">
      <div>
        <input type="checkbox" />Checkbox 1
      </div>
      <div>
        <input type="checkbox" />Checkbox 2
      </div>
      <div>
        <input type="checkbox" />Checkbox 3
      </div>
      <div>
        <input type="checkbox" />Checkbox 4
      </div>
      <div>
        <input type="checkbox" />Checkbox 5
      </div>
      <div>
        <input type="checkbox" />Checkbox 6
      </div>
      <div>
        <input type="checkbox" />Checkbox 7
      </div>
      <div>
        <input type="checkbox" />Checkbox 8
      </div>
      <div>
        <input type="checkbox" />Checkbox 9
      </div>
      <div>
        <input type="checkbox" />Checkbox 10
      </div>
    </div>
  </div>
</div>

关于javascript - 如何使用 html 和 CSS 在一个 div 中添加复选框列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40355308/

相关文章:

javascript - 新手使用 Marionette 和 JQuery-Mobile (JQM)

javascript - 访问附加 html 中的 ng-repeat 重复数据

HTML CSS : Two elements in a div with fluid background colour

表单的 HTML 和 CSS 格式

css - md-select 悬停打开选择选项

javascript - 具有自动高度的表单面板内的复合字段

javascript - 从 app.js 执行时,函数内的配置找不到文件

javascript - 使用 onclick 功能在电子邮件上发送 wp 帖子标题

javascript - 当选择父选项 Js、Jquery 时,如何自动选择子选项

javascript - 显示内容侧边栏的背景 "Jumps"