在我创建的这个模型中,每当鼠标悬停在主导航上的按钮上时,我都会尝试在每个按钮下面创建一个自定义箭头形状。但是,每个按钮的宽度会有所不同,我需要它看起来一样。我如何在CSS中实现这一目标? Click Here看看我想要实现的目标'我是新的'链接。
到目前为止,这就是我在style.css中所拥有的:
.main_nav_inside {
margin: 0 auto;
margin-top: -130px;
position: relative;
z-index: 1;
}
.main_nav_inside ul {
list-style-type: none;
margin: 0;
float: right;
}
.main_nav_inside ul li {
display: inline-block;
float: left;
font-family: 'Roboto', sans-serif;
font-size: 20px;
font-weight: 500;
text-transform: uppercase;
}
.main_nav_inside ul li a {
display: block;
top: 0;
padding-left: 20px;
padding-right: 20px;
padding-top: 50px;
height: 130px;
color: #ffffff;
}
.main_nav_inside ul li a:hover {
padding-bottom: 5px;
width: 100%;
background-color: #2F2F2F;
}
.main_nav_inside ul li a:hover:before {
padding-bottom: 20px;
width: calc(2% + 30px);
background-color: #000000;
content: '';
position: absolute;
margin: 0 auto;
left: inherit;
margin-left: -20px;
margin-right: 0;
top: 120px;
height: 20px;
background: #000000;
-webkit-transform: skew(0deg, 0deg);
-moz-transform: skew(0deg, -6deg);
-ms-transform: skew(0deg, -6deg);
-o-transform: skew(0deg, -6deg);
transform: skew(0deg, 15deg);
z-index: -1;
}
.main_nav_inside ul li a:hover:after {
padding-bottom: 20px;
width: calc(10% / 2);
background-color: #000000;
content: '';
position: absolute;
margin: 0 auto;
right: inherit;
margin-left: -35px;
margin-right: 0;
top: 120px;
height: 20px;
background: #000000;
-webkit-transform: skew(0deg, 0deg);
-moz-transform: skew(0deg, -6deg);
-ms-transform: skew(0deg, -6deg);
-o-transform: skew(0deg, -6deg);
transform: skew(0deg, -15deg);
z-index: -1;
}
以下是此页面的HTML:
<header id="header_inside">
<div class="main_logo_white"><a href="{{ siteUrl }}"><img src="{{ siteUrl }}/images/ssumc_logo_white.png"></a></div>
{% set parents = craft.entries.section('menu').level(1).limit(5) %}
<nav class="main_nav_inside">
<ul>
{% nav parent in parents %}
<li>
{{ parent.getLink() }}
{% ifchildren %}
<ul class="dropdown">
<li>{% children %}</li>
</ul>
{% endifchildren %}
</li>
{% endnav %}
</ul>
</nav>
</header>
这个网站正在使用Craft CMS构建......并不重要。
答案 0 :(得分:0)
I was able to create the shape using border-top, border-left and border-right. But the bottom tip seems to stay flat and doesn't have a point to it. No matter what numbers you adjust in the border width of top, left or right the tip will stay flat.
.main_nav_inside ul li a:hover:after {
top: 100%;
left: 0;
right: 0;
content: " ";
position: absolute;
border-top: 20px solid #000000;
border-left: 50px solid rgba(0, 0, 0, 0);
border-right: 50px solid rgba(0, 0, 0, 0);
}