How to center your HTML button

How to center your HTML button

How to center your HTML button itself? This is easy to find the idea. Set the center attribute in its parent tag, as follows:

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

or:

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

Center the button horizontally

Button is an inline block-level element display:inline-block;

So the solution is very simple, there are two ways:

Method 1:

 <div style="text-align:center">  
 <button>Button Center</button>                      
 </div>

Method 2:

<div>    
<button style="display:block;margin:0 auto">Button centered</button>                      
</div>

This is the end of this article on how to center your HTML button. For more information on centering HTML button, please search previous articles on 123WORDPRESS.COM or continue browsing the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Angular Cookie read and write operation code

>>:  10 Website Usability Tips Everyone Should Know

Recommend

Installation tutorial of mysql8.0rpm on centos7

First, download the diagram 1. First uninstall th...

js version to realize calculator function

This article example shares the specific code of ...

Vue3 setup() advanced usage examples detailed explanation

Table of contents 1. Differences between option A...

Detailed explanation of how to adjust Linux command history

The bash history command in Linux system helps to...

Ubuntu 20.04 connects to wifi (2 methods)

I recently installed Ubuntu 20.04 and found that ...

An article explains Tomcat's class loading mechanism

Table of contents - Preface - - JVM Class Loader ...

Telnet is moved to busybox-extras in Alpine image

The telnet in the Alpine image has been moved to ...

Practice of using Tinymce rich text to customize toolbar buttons in Vue

Table of contents Install tinymce, tinymce ts, ti...

Detailed explanation of how to install MariaDB 10.2.4 on CentOS7

CentOS 6 and earlier versions provide MySQL serve...

Detailed steps for installing Harbor, a private Docker repository

The installation of Harbor is pretty simple, but ...

Summary of using the exclamation mark command (!) in Linux

Preface Recently, our company has configured mbp,...

How to add website icon?

The first step is to prepare an icon making softwa...

How to use domestic image warehouse for Docker

1. Problem description Due to some reasons, the d...