Search code examples
htmlioscsswebkittext-align

CSS property text-align being overridden by iOS Webkit for submit button


The following is my CSS code for a form's submit button:

.submit {
    -webkit-appearance: none !important;
    text-align: center !important;
    border-radius: 0rem;  
    color: rgb(63, 42, 86);
    display: inline-block;
    float: right;
    border: none;
    font-size: 14px;
    border-left: 0.05rem solid rgb(63, 42, 86);
    width: 3.6rem;
    height: 2.2rem;
    line-height: 1.75rem;
    transition: background-color 0.2s;
    background-color: transparent;
}

After some initial formatting issues on iOS, I implemented -webkit-appearance: none which fixed most of the problems. But the "Submit" text for the Submit button is now right-aligned instead of centered on iOS, as shown in this image: http://ben-werner.com/screenshot/01.png

On the desktop version using chrome and safari however, the text displays centered as it should: http://ben-werner.com/screenshot/02.png

I don't think it is a specificity issue, as the !important declaration of text-align: center should prevent anything else in my CSS overriding it.

Does anyone have an idea what is happening on the iOS device that causes the Submit text to function differently? Any help is much appreciated, thanks!

CodePen Link: https://codepen.io/benwerner01/pen/BqErOE (Note: the html formats correctly on the CodePen site, but the same code running within safari or chrome on iOS breaks the button. I have hosted the code from CodePen at https://ben-werner.com , to demonstrate that on mobile it displays incorrectly)


Solution

  • Ok, I know what is happening now. You are giving your submit button a specific width and height that is affecting the text-align on iOS devices. Removed the width and height values and your text will align center on iOS devices. I would also use padding to give your button the desired width and height instead of those properties.

    .submit#mc-embedded-subscribe {
     border-radius: 0 !important;
     -webkit-appearance: none !important;
     color: rgb(63, 42, 86);
     float: right;
     border: none;
     font-size: 14px;
     border-left: 0.05rem solid rgb(63, 42, 86);
     /*     width: 3.6rem;
           height: 2.2rem; */
     text-align: center !important;
     text-align: -moz-center !important;
     text-align: -webkit-center !important;
     line-height: 1.75rem;
     transition: background-color 0.2s;
     background-color: transparent;
     margin: 0 auto;
     }