【发布时间】:2019-01-24 19:05:15
【问题描述】:
所以,我正在尝试为我的网站制作一个漂亮的导航菜单栏动画/过渡,以创建一个漂亮的外观效果。我的目标是只使用 CSS,而不是添加任何使事情复杂化的 javascript。 This link has the kind of animation我在找。只是给大家一个思路。 (浏览 W3 Schools 看看我在寻找什么动画)。
这里的想法是将topnav的background-color从一个页面更改为另一个页面作为平滑过渡。
这是我目前的 CSS 样式。我喜欢我目前的样式,但我只想添加从页面到页面的过渡,以便 background-color 以某种方式像滑块一样
ul.topnav li a:hover:not(.active) {
background-color: #4d4dff;
transition: 0.5s;
}
ul.topnav li a.active {
background-color: #00cc99;
color: black;
/* I would like to add in some sort of animations / transition here. */
}
<ul class="topnav">
<label for="toggle">☰</label>
<input type="checkbox" id="toggle">
<div class="menu">
<li><a href="#" class="active">Home</a>
<!--Background when active-->
<li><a href="#">About</a></li>
<li><a href="#">Portfolio</a></li>
<!--If I click on this page, it would transition the background COLOR to this page-->
<li><a href="#">Gallery</a></li>
<li><a href="#">Contact Me</a></li>
</div>
</ul>
编辑评论以回应穆尔贾扬
在此处查看此示例 https://youtu.be/oCUCWnbre0k?t=1014 并遵循此代码。
HTML
* {
margin: 0;
padding: 0;
}
.navigation {
margin: 200px 20px;
background: #383838;
color: #FFF;
overflow: hidden;
height: 50px;
width: 1000px;
box-shadow: 0 2px 10px 2px rgba(0, 0, 0, 0.2);
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
.navigation li {
width: 100px;
border-bottom: 1px solid #666;
border-right: 2px ridge #585858;
float: left;
list-style-type: none;
font-family: 'ambleregular';
font-weight: normal;
font-size: 15px;
line-height: 28px;
padding: 10px 10px 10px 10px;
-webkit-transition: all .9s;
-moz-transition: all .9s;
-o-transition: all .9s;
-ms-transition: all .9s;
transition: all .9s;
}
.navigation li:hover {
background: #FE980F;
border-bottom: 1px solid #FFF;
}
.navigation li a {
text-decoration: none;
color: #FFF;
}
.navigation li a:hover {
color: #333;
}
/* Search box */
.search_box {
float: right;
border: 1px solid #3C3C3C;
background: #FFF;
border-radius: 0.3em;
-webkit-border-radius: 0.3em;
-moz-border-radius: 0.3em;
-o-border-radius: 0.3em;
position: absolute;
margin-top: 8px;
margin-right: 15px;
width: 228px;
left: 765px;
top: 204px;
}
.search_box form input[type="text"] {
border: none;
outline: none;
background: none;
font-size: 12px;
color: #acacac;
width: 75%;
padding: 5px;
}
/* Final STEP */
.search_box form input[type="submit"] {
border: none;
cursor: pointer;
background: url(images/search.png) no-repeat 0px 7px;
position: absolute;
right: 0;
width: 20px;
height: 25px;
}
<body bgcolor="#faf7fd">
<ul class="navigation">
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
<div class="search_box">
<form>
<input type="text" value="Search" onfocus="this.value = ''; {this.value='Search' ;}">
<input type="submit " value=" ">
</form>
</div>
</body>
【问题讨论】:
标签: html css css-transitions css-animations navigationbar