html - 在 div 中垂直居中复选框

标签 html css checkbox vertical-alignment

我在 div 中有一个 checkbox,它的显示位置高于我希望它与之对齐的文本。

这是它在 Firefox 中的显示方式:

enter image description here

如您所见,复选框 仅比文本高几个像素。我尝试应用各种填充/边距,包括负值,但无济于事。

HTML:

<div id="read-confirm-box">
  I Have read the above 
  <input type="checkbox" id="checkbox" />
</div>

CSS:

#read-confirm-box
{
    color: #FFF;
    width: 180px;
    font-size: 12px;
    background-color: #333;
    border-radius: 3px;
    padding: 6px 11px;
    margin: auto;
    float: left;
}

#checkbox 
{
    /* Empty */
}

最佳答案

检查这个jsFiddle

HTML

<div id="read-confirm-box">
  I Have read the above 
  <input type="checkbox" id="checkbox" />
</div>

CSS

#read-confirm-box
{
    color: #FFF;
    width: 180px;
    font-size: 12px;
    background-color: #333;
    border-radius: 3px;
    padding: 6px 11px;
    margin: auto;
    float: left;
}

#checkbox 
{
    position: relative;
    top: 3px;
}

关于html - 在 div 中垂直居中复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22304904/

相关文章:

javascript - 如何将光标放在文本区域时弹出模式

html - 隐藏一个 <tr>,同时仍然将它包含在宽度计算中

javascript - 如何重复onclick事件?

javascript - 样式复选框为正方形

javascript - 复选框 - 选中取消选中功能不起作用

javascript - AngularJS如何获取 bool 值

javascript - HTML5 API 与 HTML5 Javascript API

html - ie9 中的 'not' css 选择器

javascript - HTML5 视频控件不起作用

html - 图像在 IE 上不重叠