css - 为什么相同的行高在两个不同的 Chrome 版本中呈现不同?

标签 css

<分区>

我显示的按钮如下:

.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>

一切正常,除了在移动设备上查看时:

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

文本显示在 div 内部比以下情况高大约 2 个像素:

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

为什么会这样?它是如何修复的?

最佳答案

你可以在这里尝试依赖 flex 模型:

您可以在手机上测试的几个示例:

.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>

关于css - 为什么相同的行高在两个不同的 Chrome 版本中呈现不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58016764/

相关文章:

css - 页脚没有放在正确的位置

javascript - Soundcloud iframe 小部件定制

jquery - Bootstrap 导航子菜单根据页面限制向左或向右浮动

javascript - 谷歌图表 : Y-Axis numbers not visible

javascript - CSS/JS : Placing a toolbar on the left side of the screen without overlapping with existing page elements

html - 如何使用 Perl 将文件中的 CSS 定义合并到内联样式属性中?

html - 桌面屏幕尺寸的背景图片太小?

css - 为什么这个愚蠢的定位会导致这个网站发生变化?

javascript - 单击按钮后重复/添加 div

html - 从链接的图像中删除下划线