html - 表单元素没有移动到中心

标签 html css twitter-bootstrap

我是网络编程的新手。

我的 head 标签中有一个样式标签,如下所示:

<style type="text/css">
  .center {
      float: none;
      margin-left: auto;
      margin-right: auto;
  }

我使用 Twitter Bootstrap 。我将 form 包裹在 div block 中

<div class="center"
    <form>
      <fieldset>
        <legend>Legend</legend>
        <label>Label name</label>
        <input type="text" placeholder="Type something…">
        <span class="help-block">Example block-level help text here.</span>
        <label class="checkbox">
          <input type="checkbox"> Check me out
        </label>
        <button type="submit" class="btn">Submit</button>
      </fieldset>
    </form>
</div>

但是 form 元素甚至没有移动到中心。

我在哪里犯了错误?

最佳答案

这是居中的,但由于 div 是 block 元素,除非您提供一些宽度( Example 指定宽度),否则您无法找出差异

那么试试这个

 .center {
      float: none;
      margin-left: auto;
      margin-right: auto;
    text-align:center
  }
legend{
    text-align:left
}

DEMO

关于html - 表单元素没有移动到中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15631566/

相关文章:

css - 使用@font-face 不显示字体

javascript - 如何在不放置 div 的情况下检查 map 内的条件

html - SVG 中的剪切路径在 Safari 中不起作用

html - 不知道如何在 HTML/CSS 中应用自定义字体

javascript - 通过 jQuery 将事件附加到 Angular 元素

javascript - 使用 javascript/css 在鼠标悬停时禁用(不隐藏)主滚动条?

javascript - 有什么方法可以让图像自行调整为固定分辨率但看起来不会很奇怪吗?

javascript - 未加载选项卡 - Bootstrap 选项卡

javascript - Bootstrap 3 : Hidding carousel controls on first and last items not working

html - 如何让 2 个 div 继承父 div 中具有更高高度的 div 的高度?