2

I am showing a button like:

.button {
  height: 44px;
  background-color: #FF0000;
  display: block;
  margin-top: 20px;
  margin-left: 20px;
  margin-right: 20px;
  border-radius: 5px;
  border-top: none !important;
  line-height: 42px !important;
}
<div class="button">Text</div>

Everything works perfectly, except when viewing it in mobile on:

Android 8.1.0 AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/76.0.3809.132 Mobile Safari/537.36

the text shows approximately 2 pixels higher up inside the div than with:

Android 9 AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.73 Mobile Safari/537.36

Why would that be? And how is it fixable?

disinfor
  • 10,865
  • 2
  • 33
  • 44
moo moo
  • 476
  • 5
  • 20
  • Including 1) a runable snippet and 2) screenshots would be useful. – user2864740 Sep 19 '19 at 18:09
  • 1
    are the font used the same in both browsers ? – G-Cyrillus Sep 19 '19 at 18:11
  • Possible duplicate of [Is it possible to achieve line-height consistency in all browsers?](https://stackoverflow.com/questions/4474636/is-it-possible-to-achieve-line-height-consistency-in-all-browsers) - 9 years and it's still the same battle. – disinfor Sep 19 '19 at 18:15
  • @G-Cyr Yes, everything is exactly the same. – moo moo Sep 19 '19 at 18:22
  • you are not specifing any font-familly, so they will never be the same because you will not have the default same font everywhere – Temani Afif Sep 19 '19 at 19:20

1 Answers1

2

You may try to rely on the flex model here :

a few examples that you might test on your mobiles:

.button {
  height: 44px;
  background-color: #FF0000;
 /* display: block; */
  margin-top: 20px;
  margin-left: 20px;
  margin-right: 20px;
  border-radius: 5px;
  border-top: none !important;
  /*line-height: 42px !important;*/
}

/* TEST  UPDATE */
.button {
  display: flex;
  align-items:center;
  
  
/* demo purpose */  
  /* to show middle */
    background-image:linear-gradient(to top, transparent 50%, rgba(0,0,0,0.2) 50%);
}
.fz2 {font-size:2em;}
.fmthm {font-family:verdana;}
<div class="button">Text</div>

<div class="button fz2">Text</div>

<div class="button fmthm fz2">TEXT</div>
G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129