我有一个HTML代码,该代码将div周围的链接包装了起来。
在包装链接之前,我可以使用CSS的nth-of-type来定位div,但是由于包装了链接HTML代码,它不再起作用了,大概是因为它们现在“嵌套”了吗?
我如何修改CSS以仍然将其定位为目标?
非常感谢!
示例:
在此示例中,div 3、4、5的大小均应与sp-submenu-item(50px)不同,事实并非如此。
/* START: UNnecceary code for question */
.sp-submenu-wrapper {
width: 100%;
height: 85px;
display: grid;
grid-template-columns: repeat(7, 1fr);
grid-gap: 1%;
justify-items: center;
justify-content: center;
align-items: start;
border-top: 1px solid black;
border-bottom: 1px solid black;
}
.sp-submenu-item {
margin-top: 25px;
width: 50px;
background-color: #646464;
border: 1px solid white;
border-radius: 5px;
color: white;
font-family: 'Caveat', cursive;
font-size: 20px;
text-transform: uppercase;
white-space: nowrap;
height: 35px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0px 0px 15px 2px black;
}
/* END: UNnecceary code for question */
.sp-submenu-item:nth-of-type(3), .sp-submenu-item:nth-of-type(4) {
width: 220px;
}
.sp-submenu-item:nth-of-type(5) {
width: 125px;
}
<div class="sp-submenu-wrapper">
<a href="#"><div class="sp-submenu-item">menu 1</div></a>
<a href="#"><div class="sp-submenu-item">menu 2</div></a>
<a href="#"><div class="sp-submenu-item">menu 3</div></a>
<a href="#"><div class="sp-submenu-item">menu 4</div></a>
<a href="#"><div class="sp-submenu-item">menu 5</div></a>
</div>