CSS - 在悬停状态下添加另一个元素
所有,
我有一个水平菜单栏。当用户将鼠标悬停在菜单栏中的每个链接上时,我想在链接下方显示一个小三角形。
这个小三角形不是图像,而是由 CSS 边框语法渲染的。下面的图像和代码:
这是三角形的 CSS 代码:
#css_arrow {
border-color: transparent transparent rgba(111,46,11,0.0) transparent;
border-style: solid;
border-width: 8px;
height: 0;
width: 0;
position: absolute;
top: 34px;
left: 78px;
我想将三角形添加到菜单项处于悬停状态。
有人可以建议如何将此 id 添加到悬停状态吗?我考虑过对菜单栏中的项目使用两个类,但它不起作用。这是 html 代码:
<div id="main_bar">
<ul>
<li class="maintabs maintabs_tri"><a href="#">Overview</a></li><li class="maintabs maintabs_tri"><a href="#">Collar/ Neckline</a></li><li class="maintabs maintabs_tri"><a href="#">Sleeves</a>
<ul>
<li class="s_leftright"><a href="#">Left Sleeves</a></li>
<li class="s_leftright"><a href="#">Right Sleeves</a></li>
</ul></li><li class="maintabs maintabs_tri"><a href="#">Body</a></li>
</ul>
</div>
和 CSS,它不起作用:
.maintabs_tri:hover {
border-color: transparent transparent rgba(111,46,11,1) transparent;
border-style: solid;
border-width: 8px;
position: absolute;
height: 0;
width: 0;
top: 32px;
left: 78px;
}
All,
I have a horizontal menu bar. When the user hovers over each link in the menu bar, I want to show a small triangle underneath the link.
This small triangle is not an image but is rendered by CSS border syntax. Image and code below:
Here is the CSS code for the triangle:
#css_arrow {
border-color: transparent transparent rgba(111,46,11,0.0) transparent;
border-style: solid;
border-width: 8px;
height: 0;
width: 0;
position: absolute;
top: 34px;
left: 78px;
I want to add the triangle to the menu item in hover state.
Can someone please advise how to go about adding this id to the hover state. I thought about using two classes for the items in the menu bar but its not working out. Here is the html code:
<div id="main_bar">
<ul>
<li class="maintabs maintabs_tri"><a href="#">Overview</a></li><li class="maintabs maintabs_tri"><a href="#">Collar/ Neckline</a></li><li class="maintabs maintabs_tri"><a href="#">Sleeves</a>
<ul>
<li class="s_leftright"><a href="#">Left Sleeves</a></li>
<li class="s_leftright"><a href="#">Right Sleeves</a></li>
</ul></li><li class="maintabs maintabs_tri"><a href="#">Body</a></li>
</ul>
</div>
And the CSS, which doesnt work:
.maintabs_tri:hover {
border-color: transparent transparent rgba(111,46,11,1) transparent;
border-style: solid;
border-width: 8px;
position: absolute;
height: 0;
width: 0;
top: 32px;
left: 78px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将其放置在所有项目上,但仅在悬停时显示它,即
在这种情况下,跨度将是三角形。我假设您已经正确设置了 ul 和 li 的样式。所以,在你的CSS中:
我将它嵌套在锚点内,因为这样可以最大化可点击区域。
You are going to need to place it on all items, but only display it on hover, i.e.
In this case, span is going to be the triangle. I'm assuming you've already styled your ul an li appropriately. So, in your css:
I'm nesting it within the anchor because that maximizes the clickable area.