gpt4 book ai didi

css - 无法覆盖事件链接上的线性渐变

转载 作者:行者123 更新时间:2023-11-28 02:29:00 25 4
gpt4 key购买 nike

我有一个引导导航,我添加了一个简单的 CSS 过渡。当用户将鼠标悬停在链接上时,它会向右删除并将背景颜色更改为蓝色。当用户在链接页面时 .navactive被添加到 <li>类(class)。这应该使背景颜色为纯蓝色,以便用户知道他们在该页面上。线性渐变不断覆盖它。

有没有办法

  • 覆盖过渡并使其稳定
  • 在类中禁用与 .navactive 链接的转换

谢谢

.nav li {
/* Old browsers */
background: linear-gradient(to right, #0943A7 50%, #FFFFFF 50%);
background-size: 200% 100%;
background-position: right bottom;
margin-left: 10px;
transition: all 1s ease;
}

.nav li:hover{
background-position: left bottom;
}

.navactive {
background-color: #0943A7 !important;
overflow: hidden;
transform: skewX(-18deg);
-webkit-transform: skewX(-18deg);
-ms-transform: skewX(-18deg);
}

HTML:

<nav class="navbar navbar-expand-lg navbar-light bg-faded">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="true" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse show" id="navbarResponsive">
<ul class="nav justify-content-center mx-md-auto">

<li class="<?php echo ($page == "home" ? "nav-item navactive" : "nav-item")?>">
<a class="nav-link" href="index.php">Home</a>
</li>

<li class="<?php echo ($page == "page2" ? "nav-item navactive" : "nav-item")?>">
<a class="nav-link" href="#">Page 2</a>
</li>

</ul>
</div>
</div>
</nav>

最佳答案

这里发生了两件事:

  • CSS specificity .navactive 低于 .nav li
  • background:~~~background-image的简写,background-image会覆盖background-color

.navactive 规则更改为 .nav li.navactive 应该注意特殊性。

background-image:none; 添加到 .navactive 规则将确保显示 background-color

.nav li {
/* Old browsers */
background: linear-gradient(to right, #0943A7 50%, #FFFFFF 50%);
background-size: 200% 100%;
background-position: right bottom;
margin-left: 10px;
transition: all 1s ease;
}

.nav li:hover{
background-position: left bottom;
}

.nav li.navactive {
background-color: #0943A7 !important;
background-image:none;
overflow: hidden;
transform: skewX(-18deg);
-webkit-transform: skewX(-18deg);
-ms-transform: skewX(-18deg);
}
<nav class="navbar navbar-expand-lg navbar-light bg-faded">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="true" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse show" id="navbarResponsive">
<ul class="nav justify-content-center mx-md-auto">

<li class="nav-item">
<a class="nav-link" href="index.php">Home</a>
</li>

<li class="page2 nav-item navactive" >
<a class="nav-link" href="#">Page 2</a>
</li>

</ul>
</div>
</div>
</nav>

在侧节点上,您可能希望使用 font-style:italic 而不是 skewX。

关于css - 无法覆盖事件链接上的线性渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47797532/

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