css样式中怎么让三个按钮在水平位置对齐

html-css012

css样式中怎么让三个按钮在水平位置对齐,第1张

把按钮全部放在DIV里面,然后设置DIV的样式就可以了。

<title>无标题文档</title>

<style type="text/css">

#nav{ text-align:center}

</style>

</head>

<body id="nav">

<div class="1"><input name="" type="text" value="用户名"width="150px" height="20px"/></div>

<div class="2"><input name="" type="text" value="密码" width="150px" height="20px"/></div>

<div class="3"><input name="" type="button" value="登录" />

<input name="" type="button" value="注册"/>

<input name="" type="button" value="游客"/></div>

</div>

</body>

效果如图,直接就水平对齐。

通过这样的Css样式就可以实现:

<div style="margin:0 autowidth:200px">

<input class="submit" id="btn" type="submit" value="注册" />

</div>

使用margin-left:automargin-right:auto可以让你的div居中对齐。

.style{margin-left:automargin-right:auto} 缩写形式为: .style{margin:0 auto} ,数字0 表示上下边距是0。

后面的那个width也是个很重要的属性,因为按钮的宽度非常小,所以要设置一个合适的width值才可以让按钮居中。

扩展资料

css中margin属性用法

margin简写属性在一个声明中设置所有外边距属性。该属性可以有1到4个值。格式为-margin:10px 5px 15px 20px

实例:

1、margin:10px 5px 15px 20px

上边距是 10px,右边距是 5px,下边距是 15px,左边距是 20px;

2、margin:10px 5px 15px

上边距是 10px,右边距和左边距是 5px,下边距是 15px;

3、margin:10px 5px

上边距和下边距是 10px,右边距和左边距是 5px;

4、margin:10px

所有四个边距都是 10px。