How to make a

I'm using the following code in body section.

<center><a href="contact.html">Get Started</a></center>

Is there any alternative for <center> tag?

How can I make it center without using <center> tag?

1

9 Answers

Add text-align:center;display:block; to the css class. Better than setting a style on the controls themselves. If you want to change it you do so in one place.

1

You can do this:

<div> <a href="contact.html">Get Started</a> </div> 
1

You can use css like below;

 <a href="contact.html">Get Started</a> 
1

You can put in in a paragraph

<p><a href="contact.html">Get Started</a></p> 

To align a div in the center, you have to do 2 things: - Make the div a fixed width - Set the left and right margin properties variable

<div> <div> <span>a centered div</span> </div> </div> 
1

I don't know why but for me text-align:center; only works with:

text-align: grid; 

OR

display: inline-grid; 

I checked and no one style is overriding.

My structure:

<ul> <li> <a>ElementToCenter</a> </li> </ul> 

You can use the code below:

a { display: block; width: 113px; margin: auto; } 

By setting, in my case, the link to display:block, it is easier to position the link.
This works the same when you use a <div> tag/class.
You can pick any width you want.

<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> </head> <body> <h4 align="center"> <a href="Demo2.html">Center</a> </h4> </body> </html> 
1

There's also a handy tag... whatever you put in between, gets centered. Like so:

<center> <a href..... whatever> </center> 

In your html file:

<a href="contact.html">Get Started</a> 

In your css file:

.hpbottom{ text-align: center; } 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like