What's your biggest current challenge? Have your say in Community Polls along the right column.

Center button on page

Solved

Center button on page

pije
New Member
4 0 0

I have inserted this button on a page and I would like to center it. 

How do I do that?

I tried with different CSS styles, but nothing happens...

Screenshot 2024-11-21 at 13.57.38.png

Accepted Solution (1)

rajweb
Shopify Partner
387 36 52

This is an accepted solution.

Hey @pije ,

To center the button, you can use CSS properties like flexbox or text-align. Here's how you can do it based on the type of container:

For a div Container:

f the button is wrapped inside a div, use the following styles:

Using Flexbox:

CSS:

 

div {
  display: flex;
  justify-content: center; /* Centers horizontally */
  align-items: center; /* Centers vertically (if height is defined) */
  height: 100%; /* Optional: Adjust based on parent container */
}

 

Using  text-align:

 

div {
  text-align: center;
}
button {
  display: inline-block;
}

 

For a Standalone Button

 

If the button isn't wrapped in a div , apply margin:

 

css
 

 

button {
  display: block; /* Makes it a block element */
  margin: 0 auto; /* Centers horizontally */
}

 

If you've already tried CSS but it's not working, please share:

1. The HTML structure around the button.

2. The CSS styles applied to both the button and its container.

This will help diagnose the exact issue!

 

If I was able to help you, please don't forget to Like and mark it as the Solution!
If you’re looking for expert help with customization or coding, I’d be delighted to support you. Please don’t hesitate to reach out via the email in my signature below—I’m here to help bring your vision to life!

Best Regard,
Rajat Sharma

-Need a Shopify developer?
https://rajatweb.dev/
Email: rajat.shopify@gmail.com

View solution in original post

Replies 5 (5)

rajweb
Shopify Partner
387 36 52

This is an accepted solution.

Hey @pije ,

To center the button, you can use CSS properties like flexbox or text-align. Here's how you can do it based on the type of container:

For a div Container:

f the button is wrapped inside a div, use the following styles:

Using Flexbox:

CSS:

 

div {
  display: flex;
  justify-content: center; /* Centers horizontally */
  align-items: center; /* Centers vertically (if height is defined) */
  height: 100%; /* Optional: Adjust based on parent container */
}

 

Using  text-align:

 

div {
  text-align: center;
}
button {
  display: inline-block;
}

 

For a Standalone Button

 

If the button isn't wrapped in a div , apply margin:

 

css
 

 

button {
  display: block; /* Makes it a block element */
  margin: 0 auto; /* Centers horizontally */
}

 

If you've already tried CSS but it's not working, please share:

1. The HTML structure around the button.

2. The CSS styles applied to both the button and its container.

This will help diagnose the exact issue!

 

If I was able to help you, please don't forget to Like and mark it as the Solution!
If you’re looking for expert help with customization or coding, I’d be delighted to support you. Please don’t hesitate to reach out via the email in my signature below—I’m here to help bring your vision to life!

Best Regard,
Rajat Sharma

-Need a Shopify developer?
https://rajatweb.dev/
Email: rajat.shopify@gmail.com

BrainStation23
Shopify Partner
413 62 60

Hlw @pije 
Can you share your store URL so we can investigate your problem?

Brain Station 23 PLC (Mail: js.sbu@brainstation-23.com)
- Was your question answered? Mark it as an Accepted Solution
- Did the solution not address your concern? We kindly request that share or mail your store URL with us this will enable us to collaborate more closely.
- Explore our Shopify public apps

topnewyork
Globetrotter
748 124 139

Hello, 

Please share "Store URL"

Thanks!

Need a Shopify developer?
Hire us at Top New York Web Design
For Shopify Design Changes | Shopify Custom Coding | Custom Modifications
Try Big Bulk Discount To Boost Your Store Sales with Volume/Tier Discount

Moeed
Shopify Partner
6339 1719 2076

Hey @pije 

 

Welcome to Shopify Community! Can you share your Store URL so I can have a look on it? Also, if you have password enabled then please share the password as well. Your cooperation would be greatly appreciated.

 

Best Regards,
Moeed

- Need a Shopify Specialist? Chat on WhatsApp

- Get a quick Shopify quote – Click here!

- Boost Your Sales with Affiliate Marketing - UpPromote: Affiliate & Referral


pije
New Member
4 0 0

This worked - thank you very much