如何将li元素内的复选框放在中心位置?

时间:2016-07-19 12:46:25

标签: html css position alignment center

我有一个包含div内容和带有复选框的范围的项目列表。我想将复选框范围定位到li元素的中心。

<li class="e-list e-state-default e-list-check">
    <div class="cont-bg">
       content here varies
     </div>
 <span >
 <input class="e-lv-check e-checkbox e-js e-input" type="checkbox"/>
  </span>
</li>

内容是动态加载的,因此其高度和宽度会有所不同。我无法设置填充以进行定位。尝试使用vertical-align进行定位。没有任何效果。

&#13;
&#13;
.e-list.e-state-default {
  background-color: #fff;
  border-color: #c8c8c8;
}
.e-list {
  border-bottom: 1px solid #c8c8c8;
  font-size: 12px;
}
.cont-bg {
  font-size: 17px;
  height: 100px;
  padding-left: 5px;
  padding-top: 10px;
  width: 80%;
  display: inline-block;
}
.e-list .e-lv-checkdiv {
  float: right;
}
.e-list {
  border-bottom: 1px solid #c8c8c8;
  font-size: 12px;
}
.e-list {
  line-height: normal;
  padding: 0 15px;
  cursor: pointer;
  vertical-align: middle;
}
&#13;
<ul>

  <li class="e-list e-state-default e-list-check">
    <div class="cont-bg">
      <div class="brooke">
      </div>
      <div class="listrightdiv">
        <span class="templatetext">Brooke</span>  <span class="designationstyle">HR Assistant</span>
        <div class="aboutstyle">
          Brooke provides administrative support to the HR office. Brooke provides administrative support to the HR office. Brooke provides administrative support to the HR office.
        </div>
      </div>
    </div>
    <span><input class="e-lv-check e-checkbox e-js e-input" type="checkbox" tabindex="" name="null" value="true" /> </span>
  </li>
  <li class="e-list e-state-default e-list-check">
    <div class="cont-bg">
      <div class="brooke">
      </div>
      <div class="listrightdiv">
        <span class="templatetext">Brooke</span>  <span class="designationstyle">HR Assistant</span>
        <div class="aboutstyle">
          Brooke provides administrative support to the HR office. Brooke provides administrative support to the HR office. Brooke provides administrative support to the HR office.
        </div>
      </div>
    </div>
    <span><input class="e-lv-check e-checkbox e-js e-input" type="checkbox" tabindex="" name="null" value="true" /> </span>
  </li>
</ul>
&#13;
&#13;
&#13;

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

为什么要混用<div><span>?跨越两者会给你正确的结果吗?你可以使用这样的东西:

&#13;
&#13;
.e-list,
.e-list span {vertical-align: middle; text-align: center;}
&#13;
<li class="e-list e-state-default e-list-check">
  <span class="cont-bg">
    content here varies
  </span>
  <span>
    <input class="e-lv-check e-checkbox e-js e-input" type="checkbox"/> This is centered.
  </span>
</li>
&#13;
&#13;
&#13;

如果由于某种原因,您无法将<div>更改为<span>,请使用:

&#13;
&#13;
.e-list {vertical-align: middle; text-align: center;}
.e-list div,
.e-list span {vertical-align: middle; text-align: center; display: inline-block;}
&#13;
<li class="e-list e-state-default e-list-check">
  <div class="cont-bg">
    content here varies
  </div>
  <span>
    <input class="e-lv-check e-checkbox e-js e-input" type="checkbox"/> This is centered.
  </span>
</li>
&#13;
&#13;
&#13;