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

A detailed introduction to the basics of Linux scripting

Table of contents 1. Script vim environment 2. Ho...

Detailed tutorial on deploying apollo with docker

1. Introduction I won’t go into details about apo...

A brief introduction to web2.0 products and functions

<br />What is web2.0? Web2.0 includes those ...

How to add abort function to promise in JS

Table of contents Overview Promise Race Method Re...

Detailed tutorial on installing mysql on centos 6.9

1. Confirm whether MySQL has been installed. You ...

How to install MySql in CentOS 8 and allow remote connections

Download and install. First check whether there i...

How to generate a free certificate using openssl

1: What is openssl? What is its function? What is...

XHTML tags should be used properly

<br />In previous tutorials of 123WORDPRESS....

Zookeeper stand-alone environment and cluster environment construction

1. Single machine environment construction# 1.1 D...

Some suggestions for Linux system optimization (kernel optimization)

Disable swap If the server is running a database ...

Docker network mode and configuration method

1. Docker Network Mode When docker run creates a ...

Example code for using @media in CSS3 to achieve web page adaptation

Nowadays, the screen resolution of computer monit...

Docker MQTT installation and use tutorial

Introduction to MQTT MQTT (Message Queuing Teleme...

How to set horizontal navigation structure in Html

This article shares with you two methods of setti...