gpt4 book ai didi

html - Flexbox 忽略链接上的填充和宽度

转载 作者:太空宇宙 更新时间:2023-11-04 15:56:50 24 4
gpt4 key购买 nike

基本上,我有一个使用 flexbox 的导航,并且一切正常。然而,当最近回顾它时,我注意到 <a> Li 内部的 与 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>

这是代码笔:https://codepen.io/danielvickerssa/pen/ZyjqRr

最佳答案

如果添加 display: flex对于您的列表项,它们将强制子元素(在本例中为 <a>)拉伸(stretch)容器的整个高度。

这是 flex 容器中的默认设置 – align-items: stretch

只需将此添加到您的代码中:

li {
display: flex;
}

https://codepen.io/anon/pen/JJBePq

关于html - Flexbox 忽略链接上的填充和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44952486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com