如何在div元素中水平居中按钮元素? [英] How can I horizontally center a button element in a div element?

查看:2845
本文介绍了如何在div元素中水平居中按钮元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想将CSS添加到div元素(例如< div style =text-align:center;> )。我只想将CSS代码添加到按钮元素。

 < div> 
<按钮>按钮< /按钮>
< / div>

在这种情况下,我该如何将按钮水平居中?

解决方案

button {
margin:0 auto;
display:block;
}

<覆盖> 按钮{margin:0 auto; display:block;}

< div> < / button>>按钮< / button>< / div>

I don't want to add CSS to my div element (e.g. <div style="text-align: center;">). I only want to add CSS code to the button element.

<div>
    <button>Button</button>
</div>

How can I center the button horizontally in this case?

解决方案

button {
    margin:0 auto;
    display:block;
}

button {
  margin: 0 auto;
  display: block;
}

<div>
  <button>Button</button>
</div>

这篇关于如何在div元素中水平居中按钮元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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