如何让你的html button本身居中的实现

(编辑:jimmy 日期: 2024/9/20 浏览:2)

如何让你的html button本身居中呢? 这个很好找思路, 在其父标签中设置居中属性啊, 如下:

<html>
<body>
 
<center><button onClick="myClick()">hit me</button></center>
 
<script>
function myClick()
{
 alert("123");
}
</script>
</body>
</html>

或者:

<html>
<body>
 
<div align="center"><button onClick="myClick()">hit me</button></div>
 
<script>
function myClick()
{
 alert("123");
}
</script>
</body>
</html>

按钮水平居中

button是一个行内块级元素display:inline-block;

所以处理方式很简单,可以用以下两种方式:

方式一:

 <div style="text-align:center">  
 <button>按钮居中</button>                      
 </div>

方式二:

<div>    
<button  style="display:block;margin:0 auto">按钮居中</button>                      
</div>