html - 垂直居中似乎不适用于 Chrome 移动版中的某些字体

标签 html css google-chrome typeface font-family

我不明白为什么在 headings 、 paragraph 、 span 等容器元素内似乎不可能垂直居中 .. 在移动版 Chrome 中使用某些字体。似乎在移动版 Firefox 中效果更好。 一个例子 : Open-Sans 适用于 Firefox 移动版和 Chrome 移动版。例如,使用字体系列 Raleway 垂直居中似乎仅适用于 Firefox 移动版。

    #x-wrapper {
      
      position:absolute;
      left:100px;
      font-family:'Open Sans',sans-serif;font-weight:400;
      
     }
    
    #y-wrapper {
      position:absolute;
      left:200px;
      font-family:'Oswald',sans-serif;font-weight:400;
     }
    
    .circle {
      width:50px;
      height:50px;
      border:1px black solid;
      border-radius:25px;
      }
      
      .hello{
        position:relative;
        height:100%;
        width:100%;
       }
      
      .hello h5 {
        position:absolute;
        top:50%;
        left:50%;
        transform:translate(-50%,-50%);
        margin:0px;
<!DOCTYPE html>
  <head>
    <link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
  </head>

  <body>
    <div id="x-wrapper" class="circle">
      <div class="hello">
        <h5>hello</h5>
      </div>
    </div>
    <div id="y-wrapper" class="circle">
      <div class="hello">
        <h5>hello</h5>
      </div>
    </div>
  </body>
</html>

最佳答案

我会发表评论来提问,但还没有足够的代表:/

你试过这样的事情吗:

.circle {
    display: flex;
    align-items: center;
    justify-content: center;
}

使用 flexbox , 它们在尝试垂直对齐文本元素时非常有用。 Flexbox 也与大多数浏览器兼容:link

关于html - 垂直居中似乎不适用于 Chrome 移动版中的某些字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35846819/

相关文章:

html - 让我的网站流畅

javascript - 除了使用自定义 CSS 和 html 之外,还有其他方法可以显示从 API 获取的推文吗?

html - Chrome 9 中奇怪的边距错误

html - 媒体查询中的响应式网格布局中断

html - 如何将 div 的左、右、上边距设置为相等

javascript - 倒数计时器css分析

google-chrome - Font Awesome 图标未在 Chrome 中显示,这是与 MaxCDN 相关的跨源资源共享政策问题

javascript - Chrome 无法读取 style.display 值

html - 如何用CSS制作垂直渐变线

html - 如何让我的 div 框放在一起