【问题标题】:How align in horizontal the menu?如何水平对齐菜单?
【发布时间】:2019-01-02 10:29:10
【问题描述】:

我正在尝试对齐我的文本(水平),但我的努力没有奏效

.menu{
    background: hsla(290,60%,70%,0.3);
    list-style: none;
}
.menu li{
        width: 200px;
}
.menu li a{
    padding: 8px 16px;
    float:center;
    display: inline;
    text-align: right;
    text-decoration: none;
}
.menu li a:hover{

    background-color: hsla(200,100%,40%,0.2);
}

【问题讨论】:

标签: css menu alignment


【解决方案1】:

试试这个:

ul {
  list-style: none;
}

a {
  text-decoration: none;
}

.menu {
  display: flex;
  justify-content: center;
  background: hsla(290,60%,70%,0.3);
  padding: 8px 16px;
}
.menu li{
  flex: 1;
  text-align: center;
}
.menu li a:hover{
  background-color: hsla(200,100%,40%,0.2);
}
<ul class="menu">
  <li><a href="/">thing</a></li>
  <li><a href="/">stuff</a></li>
  <li><a href="/">things</a></li>
  <li><a href="/">stuffs</a></li>
  <li><a href="/">thingsstuff</a></li>
</ul>

【讨论】:

  • 谢谢!我会尝试! :D
【解决方案2】:

查看此演示。你已经使用float:center; 使用float:left 反对它。应该可以的。

Demo

【讨论】:

  • 如果它对你有帮助,那么为什么要投反对票,我很困惑为什么我会投反对票。我想知道答案,因为它让我失去了给出问题答案的动力。谢谢
  • 我认为由于该问题获得了否定投票,因此任何答案都会自动获得否定。我的也是这样:(
猜你喜欢
  • 2015-02-02
  • 2011-02-21
  • 2017-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-28
  • 2012-09-06
相关资源
最近更新 更多