无法填写李标签

时间:2016-02-22 19:18:59

标签: css

现在试图让它工作一段时间。我正在尝试为我的新网站创建菜单,我设置了nav,ul和li标签。当然,我的实际按钮略大于文本显示,我希望A填写LI标签。

nav {
  width: 100%;
  min-width: 800px;
  background-color: #EDEDED;
}
nav a {
  color: #000;
  text-decoration: none;
  display: block;
  height: 100%;
  width: 100%;
}
nav ul {
  list-style: none;
  margin: auto auto auto 10vw;
  height: 2em;
  display: block;
}
nav ul li {
  display: inline-block;
  background-color: #DEDEDE;
  vertical-align: middle;
  padding: 0 50px 0 50px;
  height: 2em;
  line-height: 2em;
}
nav ul li:hover {
  background-color: #FF0000;
}
<nav>
  <ul>
    <li><a href='index.php'>Home</a>
    </li>
    <li><a href='index.php'>Home</a>
    </li>
    <li><a href='index.php'>Home</a>
    </li>
  </ul>
</nav>

我觉得我已经尝试了一切:

How do I make an <a> tag the size of it's parent <li> tag for larger clickable region?

Stretching <a> tag to fill entire <li>

Expand an <a> tag to fill the space

我觉得我的代码应该给出相同的结果。有人可以指出我犯了什么错误吗?

2 个答案:

答案 0 :(得分:5)

通过在锚点上添加display:block,您有了正确的想法,但是列表项上的填充正在影响结果。将该填充移动到锚点上,然后全部设置。

&#13;
&#13;
nav {
  width: 100%;
  min-width: 800px;
  background-color: #EDEDED;
}
nav a {
  color: #000;
  text-decoration: none;
  height: 100%;
  width: 100%;
  display: block;
  padding: 0 50px 0 50px;
  box-sizing:border-box;
}
nav ul {
  list-style: none;
  margin: auto auto auto 10vw;
  height: 2em;
  display: block;
}
nav ul li {
  display: inline-block;
  background-color: #DEDEDE;
  vertical-align: middle;
  height: 2em;
  line-height: 2em;
}
nav ul li:hover {
  background-color: #FF0000;
}
&#13;
<nav>
  <ul>
    <li><a href='index.php'>Home</a>
    </li>
    <li><a href='index.php'>Home</a>
    </li>
    <li><a href='index.php'>Home</a>
    </li>
  </ul>
</nav>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

从ul li中删除填充:

nav ul li {padding:0px;}

如有必要,请将其添加到导航栏中:

nav ul li a {padding:0px 50px;}