【问题标题】:Links are display into two rows (React, css)链接显示为两行(React,css)
【发布时间】:2020-12-09 08:30:30
【问题描述】:

我有一些Header:

<header>
 <div>                              
  <Link to="/" class="navbar-brand">Home</Link>
  <Link to="/test" class="navbar-brand">Test</Link>
  <Link to="/test2" class="navbar-brand">Test2</Link>
  <Link to="/test3" class="navbar-brand">Test3</Link>
 </div>
</header>

进入css我只得到了这个:

header {
  background: rgb(73, 176, 236);
  display: flex;
  align-items: center;
} 

当我尝试将其显示到 phone 时,看起来 links 分为 2 行。

有可能以某种方式使其更小以显示为一行?

手机屏幕:

【问题讨论】:

  • 进入手机是什么意思?没看懂
  • 你能加个截图或者小提琴吗?
  • 当然,请查看更新 - 当我在手机上打开我的网站时,它看起来像图片上的样子
  • 如果你给我一个小提琴会很棒,但试试这个:'flex:1 0 auto'在标题选择器上这将防止你的flex容器缩小,但是如果你想显示这些文本更好,我建议你用 rem 设置你的字体,我也能想到很多其他的解决方案。
  • 好的 - 你把这两个作为答案:我的意思是 flex 并添加请rem

标签: css reactjs header navbar nav


【解决方案1】:

你可以试试这个来防止你的弹性容器缩小:

header {
  background: rgb(73, 176, 236);
  display: flex;
  align-items: center;
  flex: 1 0 auto
} 

此外,为了获得更好的 UI,您可以针对相对单位,例如 rem。这是代理的基本字体大小(在大多数浏览器上为 16 像素)。

font-size: 1rem;

然后根据视口更改基本字体:

@media only screen and (max-width: 600px) {
  body {
      font-size: 12px;
  }
}

这将允许您进行扩展,因为您用于选择器的所有 rem 单位现在将相应地增加和减少。

【讨论】:

  • 我刚刚开始使用 css/react,因为我主要关注后端 - C#/Oracle
  • 我明白...这是一个值得探索的有趣空间 :)
猜你喜欢
  • 2014-05-09
  • 1970-01-01
  • 1970-01-01
  • 2019-09-25
  • 2013-06-20
  • 2019-12-05
  • 1970-01-01
  • 2014-05-17
  • 2020-12-04
相关资源
最近更新 更多