Jump to content

Align the coded button to the center horizontally in the selector

Recommended Posts

Posted

How can I align the button to the center within the selector? This button was coded with simple HTML and CSS, and for some reason it's aligned to the left.

 

HTML:

<a href="#" class="btt"> Back to Top </a>

 

CSS:

.btt {

  color: white;

  font-weight: bold;

  text-align: center;

  display: inline-block;

  background: black;

  padding: 8px 24px;

  border-radius: 100px;

}

 

.btt:hover {

  background-color: #FF8282;

}

 

Screenshot 2024-10-10 at 10.17.11 PM.png

  • Replies 1
  • Views 492
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

Posted (edited)

Hi @ani168, Please give this updated code a try and let me know how it works for you:

<div class="button-container">
    <a href="#" class="btt"> Back to Top </a>
</div>

<style>
.btt {
  color: white;
  font-weight: bold;
  text-align: center;
  display: inline-block;
  background: black;
  padding: 8px 24px;
  border-radius: 100px;
  width: fit-content;
}

.btt:hover {
  background-color: #FF8282;
}

.button-container {
  display: flex;
  justify-content: center;   /* Horizontally center the button */
  align-items: center;       /* Vertically center the button */
}
</style>

  

 

 

Screenshot 2024-10-11 at 10.15.21.png

Edited by Spark-Plugin

- Answered by Iuno from sparkplugin.com

forumsignature-recommendedcopy2.png.0579645eb1430dc7c1059541dc6456c6.png

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.