How can I align two buttons in the center on mobile?

Topic summary

Main issue: Center two buttons on mobile in a Shopify banner so they appear in the middle below the text.

Attempts and feedback:

  • A generic CSS approach (setting the button container and buttons to block with auto margins) was suggested but didn’t work, likely due to existing custom CSS affecting positioning. The OP was advised to comment out prior code and/or share the store URL (provided: calinatural.store).

Implemented solution:

  • Edit theme code (Online store → Theme → Edit code) and add mobile-only CSS (max-width: 480px) in base.css/theme.css.
  • Target the specific banner sections’ .banner__buttons by ID and use absolute positioning with adjusted top/left percentages and display: block !important to visually center the buttons beneath the text.
  • Earlier absolute-position code with fixed pixel offsets was replaced by refined rules using percentages per banner section.

Outcome:

  • The updated CSS from BSS-Commerce achieved the desired centered placement on mobile. The OP confirmed it worked.

Notes:

  • Section-specific IDs were used; if sections change, selectors and top/left values may need updates.
  • Images were provided to show the desired center placement under the text.
Summarized with AI on January 31. AI used: gpt-5.

Hello! I was wondering if someone can help me with a code for these 2 button allignments, I would be grateful!
I also have already added a code for some button allignments if that’s needed to know.

I want them to be in the center middle, thank you!

try this one :wink:

.button_parent_container{
box-sizing:border-box;
}

.your_button_class{
display:block;
margin:0 auto;
max-width:max;
}

Hi @BudeanuJr

Please follow these steps:

  • Step 1: Go to Online store => Theme => Edit code

  • Step 2: Search file “base.css” or “theme.css” and add code at the end:
@media screen and (max-width: 480px) {
    #shopify-section-template--16887080157450__4f11a828-2cb0-400f-974c-aff31e077f1b .banner__buttons {
        position: absolute;
        z-index: 10;
        opacity: 0.5;
        top: -130px ;
        left: 190px;
    }
  }

  • Step 3: Save and see the result. You will get the result like this:

I hope that this can help you solve the issue.

@mavsalqueza I tried, didn’t worked.
Maybe because I already have a code that moved the buttons? I have no idea to be honest.

Hello, @BSS-Commerce

In that photo I want that button to be in the blue area, right below the text in the middle if it’s possible.

Thank you!

@BudeanuJr can you share the shop url so we can check it :smiling_face:

yes it could be. Try to comment out first your existing code then try the given code again, or you can share the shop url so we can check it.

Hi @BudeanuJr

Please follow these steps:

  • Step 1: Open Theme => Edit code

  • Step 2: Search file “base.css” or “theme.css” and add code at the end (if you used our above code, remove it and replace it with new code)
@media only screen and (max-width: 480px) {
    #Banner-template--16887080157450__4f11a828-2cb0-400f-974c-aff31e077f1b .banner__buttons {
          top: 110%;
          left: 28%;
          display:block !important;
    }

    #Banner-template--17393143677194__22767b08-177d-4651-8efb-9a4039c18d10 .banner__buttons {
          top: 150%;
          left: 32%;
          display:block !important;
    }
}

  • Here are the results:

I hope that it will also work for you.

1 Like

Sure, @mavsalqueza
https://calinatural.store

@BSS-Commerce it worked, thank you so much for the help!

1 Like