html - 如何使表格相对于标题居中?

标签 html css css-position margin navbar

我有一个固定的侧导航栏。在我有一个标题和正文内容,我希望表单相对于标题居中。

HTML

<body>
  <div id="sideNav">
  SideNav
  </div>
  <div id="mainContent">
    <div id="header">
      <div>
        <h3>
        Header
        </h3></div>

    </div>
    <div class="body-content">
      <form id="form1">
      <h3>
      Form
      </h3>
        <div id="formset">
          <table>
            <tr>
              <td>
                <label>Login</label>
              </td>
              <td>
                <input type="text" />
              </td>
            </tr>

          </table>
        </div>

      </form>
    </div>
  </div>
</body>

CSS

* {
  margin: 0;
  padding: 0;
}

body {
  position: relative;
}

#sideNav {
  width: 150px;
  height: 100%;
  background-color: #6bc7cc;
  position: fixed;
  width: 15%;
}

#mainContent {
  background-color: Aqua;
  height: 100%;
  position: absolute;
  left: 15%;
  right: 0;
}

#header {
  width: 100%;
  height: 50px;
  background-color: #fcb;
}

.body-content {
  margin: 45px;
}

#formset {
  width: 500px;
  margin: 0 auto;
}

Fiddle Here

最佳答案

尝试使用它可能对您有帮助,而不是在#formset 中设置样式

#form1{
    display: table;
    margin: 0 auto;
}

#formset{
  width:none;
  margin: 0 auto;
}

关于html - 如何使表格相对于标题居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40904629/

相关文章:

jquery - 如何改变 JQuery/CSS 元素的形状?

javascript - 定义 JQuery 函数

css - 正文 : overflow-x - still able to scroll over with trackpad

jQuery UI Draggable 在绝对定位项下方拖动

html - 内联导航示例不起作用

html - 菜单的无序列表没有间隔

css - Bulma 无法在 Laravel 5.6 上工作

html - 相关网站布局不适用于段落

javascript - 当将鼠标悬停在其中一个 td 上时,如何更改多个 td 的类别?

python - 使用 Django 运行 bash 脚本