【发布时间】:2017-12-10 16:08:06
【问题描述】:
基本上,我有一个使用 flexbox 的导航,并且一切正常。但是,最近回顾它时,我注意到 Li 中的 <a> 与 Li 本身的大小不同,因此不能使整个 Li 可点击。
我尝试了许多不同的方法来使<a> 的大小相同,当我向它们在检查器中显示为具有填充但填充不可点击的链接添加填充时...
.header .navigation {
display: block;
width: 100%;
position: relative;
}
.header .navigation ul {
margin: 0;
padding: 0;
display: flex;
flex-direction: row;
}
.header .navigation ul li {
float: none;
display: inline-block;
background-color: #9dabc0;
border-right: 1px solid #7e899a;
border-left: 1px solid #bdc6d4;
text-align: center;
flex-grow: 1;
}
.header .navigation ul li:last-child {
background-color: #b4a042;
border-right: none;
}
.header .navigation ul li:last-child:hover {
background-color: #b49242;
}
.header .navigation ul li:last-child a {
padding: 0 5px;
text-align: center;
}
.header .navigation ul li:first-child {
border-left: none;
}
.header .navigation ul li:hover {
background: #3a495e;
}
.header .navigation ul li a {
font-size: 16px;
font-family: "Open Sans";
color: #fff;
font-weight: bold;
line-height: 59px;
text-shadow: 0.5px 0.866px 0 rgba(1, 1, 1, 0.39);
padding: 0 5px;
text-align: center;
width: 100%;
}
.header .navigation ul li ul {
left: 0px;
top: 0px;
margin-left: 0px;
display: none;
/* hide all sub menus from view */
position: absolute;
z-index: 100;
background: #9dabc0;
top: 59px;
/* this should be the same height as the top level menu -- height + padding + borders */
margin-left: 0px;
width: 100%;
}
.header .navigation ul li ul li {
border-top: 1px solid #7e899a;
border-bottom: 1px solid #bdc6d4;
border-left: none;
border-right: none;
background-color: #9dabc0;
height: 42px;
display: block;
}
.header .navigation ul li ul li:last-child {
border-bottom: none;
background-color: #9dabc0;
}
.header .navigation ul li ul li:last-child a {
padding: 10px 24px;
}
.header .navigation ul li ul li a {
font-size: 16px;
font-family: "Open Sans";
width: 100%;
color: #fff;
font-weight: bold;
text-shadow: 0.5px 0.866px 0px rgba(1, 1, 1, 0.39);
display: block;
line-height: 18px;
padding: 10px 24px;
}
.header .navigation ul li ul li:hover {
background: #3a495e;
}
.header .navigation ul li {
position: relative;
}
.header .navigation ul li:hover>ul {
display: block;
}
.header .navigation ul li li.has-children>a:after {
color: green;
content: ' ►';
font-size: 10px;
float: right;
padding-right: 10px;
vertical-align: 1px;
}
.header .navigation ul .current-menu-item:after {
color: green;
content: '▲';
position: absolute;
top: 100%;
left: 30%;
}
.header .navigation ul .sub-menu .current-menu-item:after {
content: none;
}
.header .navigation ul li.has-children>a:after {
color: green;
content: '▼';
font-size: 10px;
padding-left: 5px;
vertical-align: 1px;
}
}
<div class="header">
<div class="navigation">
<ul>
<li><a href="">Home</a></li>
<li><a href="">Engineering Castings</a>
<ul>
<li><a href="">Example</a></li>
<li><a href="">Example</a></li>
<li><a href="">Example</a></li>
</ul>
</li>
<li><a href="">Architectural Castings</a>
<ul>
<li><a href="">Example</a></li>
<li><a href="">Example</a></li>
</ul>
</li>
<li><a href="">Decorative Castings</a>
<ul>
<li><a href="">Example</a></li>
<li><a href="">Example</a></li>
<li><a href="">Example</a></li>
<li><a href="">Example</a></li>
</ul>
</li>
<li>
<a href="">Downloads</a></li>
<li>
<a href="">Gallery</a></li>
<li>
<a href="">Contact</a></li>
<li>
<a href="">Blog</a></li>
<li>
<a href="">FREE Castings Guide</a></li>
</ul>
</div>
</div>
【问题讨论】: