我正在尝试将包含登录名“用户名”和“密码”字段的字段集居中到页面中心。这是我所拥有的:

fieldset{
  border: 1px solid rgb(255,232,57);
  width: 400px;
  float: left;
}

无论窗口大小如何,我都希望字段集在窗口中居中。谷歌搜索没有产生任何帮助,例如float: centeralign: center属性。

最佳答案

没有float: center,只有左和右。 Float只是通过将块级元素从堆栈流中拉出来使它们水平排列。它与display:inline-block相似,不同之处在于它使它们与 float 方向对齐。

您想要的是将边距设置为自动。如果要居中对齐fieldset内的节点,可以向其添加text-align:center;:

fieldset{
  border: 1px solid rgb(255,232,57);
  width: 400px;
  margin:auto;
}

关于html - 使用CSS将字段集居中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7898072/

10-12 12:35
查看更多