简体   繁体   English

使文本适合flexbox容器

[英]Fit text into flexbox container

I have a navigation bar with image in the middle. 我有一个导航栏,中间有图像。 Looks similar to this: 看起来类似于:

<nav class="navigation">
   <ul class="navigation-list-1">
      <li class="navigation-list-item"><a href="#home">Home</a></li>
      <li class="navigation-list-item"><a href="#features">Features</a></li>
      <li class="navigation-list-item"><a href="#add-info">Add info</a></li>
      <li class="navigation-list-item"><img class="logo" src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.svg?v=6f4af2d2d158"></li>
      <li class="navigation-list-item"><a href="#form">Form</a></li>
      <li class="navigation-list-item"><a href="#team">Team</a></li>
      <li class="navigation-list-item"><a href="#contact">Contact</a></li>
  </ul>

And style: 和风格:

> .navigation-list-item {
list-style: none;
font-size: 15px;
font-weight: bold;
}

.logo {
  position:absolute;

width: 10vw;
left:calc(50% - (10vw/2) - (10px/2));
background: cornflowerblue;
border: 5px solid cornflowerblue;
}

ul{
  display:flex;
  margin-left:-40px;

}
li{
  flex:1;
  background:yellow;
  border:1px solid green;
  height:70px;
  line-height:70px;
  text-align:center;
}

li>a{
  text-decoration:none;
}

Now, if text in navigation item is longer than particular length, the text is spliting into next line and going outside the bar so it doesn't look good. 现在,如果导航项中的文本长于特定长度,则文本将拆分为下一行并移至栏外,因此看起来不太好。 How to make text in container always to be in one line? 如何使容器中的文本始终排成一行?

Good option for start is to add css style for text: white-space: nowrap; 开始的好选择是为文本添加CSS样式: white-space: nowrap; Another good way is to set the font-size in vw units. 另一种好方法是以vw单位设置font-size Font will be responsive depending on screen size. 字体将根据屏幕大小作出响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM