首页 > 解决方案 > css - 无法使用字体样式“幸运的家伙”垂直居中跨度

问题描述

我发现我无法使用字体样式“ Luciest Guy ”垂直居中跨度。
在此处输入图像描述

我试图申请display: flex;align-items: center;span没有工作。

应用程序.vue

<template>
  <div id="app">
    <span>Luckiest Guy Font</span>
  </div>
</template>

<script>
export default {
  name: "App",
};
</script>

<style lang="scss">
@import url("https://fonts.googleapis.com/css2?family=Luckiest+Guy&display=swap");

#app {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  background-color: grey;
  margin-top: 60px;
  span {
    font-family: "Luckiest Guy", Helvetica, Arial, sans-serif;
    font-size: 19px;
    line-height: 19px;

    display: flex;
    align-items: center;
  }
}
</style>

CodeSandbox:
https ://codesandbox.io/s/cool-browser-lh9f8?file=/src/App.vue:441-453

标签: javascripthtmlcssvue.jsflexbox

解决方案


您的代码没有问题,并且工作正常。也许您还有其他一些影响此标签的类。

你也可以设置vertical-align:baseline; 在跨度标签样式中。

.span-style{
display:flex;
align-items:center;
justify-content:center;
border:1px solid black;
height:40px;
vertical-align:baseline;
}
<div>
<span class="span-style">
Hello world
</span>
</div>


推荐阅读