使用CSS将字段集居中 [英] Center a field set with CSS

查看:117
本文介绍了使用CSS将字段集居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将包含登录名用户名"和密码"字段的字段集居中放置在页面中心.这是我所拥有的:

I'm trying to center a fieldset containing the login "username" and "password" fields to the center of the page. Here is what I have:

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

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

I want the fieldset to be centered in the window, regardless of window size. Googling produced nothing helpful, such as float: center or align: center attributes.

推荐答案

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

There is no float: center, only left and right. Float simply allows block level elements to line up horizontally by taking them out of their stack flow. It's similar to display:inline-block except it aligns them to the direction of the float.

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

What you want is to set the margins to auto. If you want to center align the nodes inside the fieldset, you can add text-align:center; to this:

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

这篇关于使用CSS将字段集居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆