• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

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

    发布者: 涵韵 | 发布时间: 2025-8-13 07:12| 查看数: 23| 评论数: 0|帖子模式

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

    3. <center><button onClick="myClick()">hit me</button></center>

    4. <script>
    5. function myClick()
    6. {
    7. alert("123");
    8. }
    9. </script>
    10. </body>
    11. </html>
    复制代码
    或者:
    1. <html>
    2. <body>

    3. <div align="center"><button onClick="myClick()">hit me</button></div>

    4. <script>
    5. function myClick()
    6. {
    7. alert("123");
    8. }
    9. </script>
    10. </body>
    11. </html>
    复制代码
    按钮水平居中
    button是一个行内块级元素display:inline-block;
    所以处理方式很简单,可以用以下两种方式:
    方式一:
    1. <div style="text-align:center">  
    2. <button>按钮居中</button>                     
    3. </div>
    复制代码
    方式二:
    1. <div>   
    2. <button  style="display:block;margin:0 auto">按钮居中</button>                     
    3. </div>
    复制代码
    到此这篇关于如何让你的html button本身居中的实现的文章就介绍到这了,更多相关html button居中内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!

    来源:互联网
    免责声明:如果侵犯了您的权益,请联系站长(1277306191@qq.com),我们会及时删除侵权内容,谢谢合作!

    最新评论

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表