【问题标题】:Make text in header responsive on all screens使标题中的文本在所有屏幕上都能响应
【发布时间】:2021-12-18 09:20:51
【问题描述】:

对于不同的屏幕分辨率,如何使“名称”文本居中对齐?我认为罪魁祸首是我将 TikTok 徽标隐藏在较小的屏幕上。提前感谢您的帮助!

HTML:

<div class="header">
  <h2 class="name">Name</h2>
  <a
    class="social-icon-header"
    href="https://www.tiktok.com/@xxx"
    target="_blank"
  >
    <i class="fab fa-tiktok fa-2x"></i>
  </a>
</div>

CSS:

/* Header */

.social-icon-header {
  display: none;
}

.name {
  text-align: center !important;
  justify-content: center !important;
  /* padding-left: 15%; */
}[![screenshots][1]][1]

【问题讨论】:

    标签: css responsive-design


    【解决方案1】:

    您可以使用flexbox,并且不要忘记设置height(在本例中为min-height:100vh)属性。如果您还想垂直居中。如果不是,您可以将其删除。如果您想制作严格响应的文本,请使用this resource

    /* Header */
    
    .social-icon-header {
      display: none;
     
    }
    
    .name {
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    <div class="header">
      <h2 class="name">Name</h2>
      <a class="social-icon-header" href="https://www.tiktok.com/@tretuser" target="_blank">
        <i class="fab fa-tiktok fa-2x"></i>
      </a>
    </div>

    【讨论】:

    • 嗨@MarioG8,感谢您的回答。我试过了,但它根本没有移动名称。我没有包括“最小高度”,因为我不想垂直居中。有没有其他方法可以居中?谢谢!
    猜你喜欢
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-22
    • 2020-12-30
    • 2020-12-19
    • 2020-07-14
    相关资源
    最近更新 更多