您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么用CSS3實現多功能下拉菜單”,在日常操作中,相信很多人在怎么用CSS3實現多功能下拉菜單問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么用CSS3實現多功能下拉菜單”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
今天要分享的這款菜單是基于CSS3的下拉菜單,功能非常強大,下拉菜單中不僅擁有背景色漸變的菜單項,而且還帶有分享按鈕的菜單項,為了讓菜單更加美觀,每一個菜單項都帶有非常漂亮的小圖標,而且在下拉菜單中還有鼠標滑過縮進的動畫特效。
接下來我們來具體解說一下實現這款CSS3下拉菜單原理和過程,代碼主要是HTML和CSS。
首先是HTML代碼,主要是兩部分,左側的下拉菜單項和右側的分享按鈕菜單,分別用了一個ul li列表:
HTML代碼:
XML/HTML Code復制內容到剪貼板
<ul class=”menu-function”>
<li>
<a href=”" title=”">CATEGORIES</a>
<ul class=”dropdown-menu categories”>
<li><a href=”" title=”">Design</a></li>
<li><a href=”" title=”">Freebies</a></li>
<li><a href=”" title=”">Tutorials</a></li>
<li><a href=”" title=”">Coding</a></li>
<li><a href=”" title=”">Inspiration</a></li>
<li><a href=”" title=”">WordPress</a></li>
<li><a href=”" title=”">Resources</a></li>
</ul>
</li>
<li><a href=”" title=”">SHOP</a></li>
<li id=”search”>
<a href=”#search” title=”">SEARCH</a>
</li>
<li id=”search-hidden”>
<input type=”text” name=”" id=”"><a href=”#search-hidden” title=”"></a>
</li>
</ul>
<ul class=”menu-share”>
<li>
<a href=”" title=”">FOLLOW US</a>
<ul class=”dropdown-menu follow”>
<li><a href=”" title=”">RSS</a></li>
<li><a href=”" title=”">Twitter</a></li>
<li><a href=”" title=”">Facebook</a></li>
<li><a href=”" title=”">Google+</a></li>
<li><a href=”" title=”">Dribbble</a></li>
</ul>
</li>
<li>
<a href=”" title=”">SHARE</a>
<ul class=”dropdown-menu share”>
<li><a href=”" title=”">Facebook</a></li>
<li><a href=”" title=”">Twitter</a></li>
<li><a href=”" title=”">Google+</a></li>
</ul>
</li>
</ul>
這個ul結構支撐了下拉菜單的基本骨架,應該還算普通。
接下來是CSS3代碼,是實現這款CSS3下拉菜單的關鍵:
CSS3代碼:
CSS Code復制內容到剪貼板
.page-menu-wrapper > ul > li {
position: relative;
float: left;
border-left: 1px solid #3d61a2;
border-right: 1px solid #3d61a2;
margin-right: -1px;
}
.menu-function {
float: left;
}
.menu-share {
float: rightright;
}
.page-menu-wrapper > .menu-function > li:first-child {
border-left: none;
}
.page-menu-wrapper > .menu-share > li:last-child {
border-right: none;
}
.page-menu-wrapper a {
position: relative;
display: block;
padding: 0 15px;
transition: all .3s ease-out;
}
.page-menu-wrapper > ul > li:hover > a {
color: #3d61a2;
background-color: #fff;
}
.page-menu-wrapper > ul > li:hover .dropdown-menu {
display: block;
}
.dropdown-menu {
display: none;
position: absolute;
width: 260px;
font-size: 18px;
font-weight: bold;
text-align: left;
background-color: #fff;
}
.dropdown-menu.categories a {
color: #000;
}
.dropdown-menu.categories a:hover {
color: #5bc4be;
margin-left: 10px;
}
#search:target a[href="#search"] {
display: none;
}
#search:target ~ #search-hidden {
display: block;
}
#search-hidden {
display: none;
padding: 0 5px;
background-color: #fff;
}
#search-hidden input {
border: none;
line-height: 24px;
width: 180px;
}
#search-hidden a {
float: rightright;
padding: 0;
width: 20px;
height: 45px;
}
#search-hidden a:before {
content: “\7d”;
left: 0;
color: #446cb3;
}
.menu-function > li > a,.menu-share > li > a {
padding-left: 40px;
}
.page-menu-wrapper a:before {
position: absolute;
left: 15px;
font-family: ‘icomoon’;
font-style: normal;
speak: none;
font-weight: normal;
font-smoothing: antialiased;
font-size: 18px;
vertical-align: middle;
}
.menu-function > li:nth-child(1) > a:before {
content: “\e048″;
}
.menu-function > li:nth-child(2) > a:before {
content: “\3b”;
}
.menu-function > li:nth-child(3) > a:before {
content: “\7d”;
}
.menu-share > li:nth-child(1) > a:before {
content: “\e0a2″;
}
.menu-share > li:nth-child(2) > a:before {
content: “\e05b”;
}
/*follow*/
.dropdown-menu.follow {
width: 223px;
}
.dropdown-menu.follow a {
padding-left: 35px;
font-size: 14px;
}
.dropdown-menu.follow a:before {
left: 10px;
}
.dropdown-menu.follow li:nth-child(1) a:before {
content: “\e0a5″;
}
.dropdown-menu.follow li:nth-child(2) a:before {
content: “\e0a2″;
}
.dropdown-menu.follow li:nth-child(3) a:before {
content: “\e04c”;
}
.dropdown-menu.follow li:nth-child(4) a:before {
content: “\e022″;
}
.dropdown-menu.follow li:nth-child(5) a:before {
content: “\e03d”;
}
.dropdown-menu.follow li:nth-child(1) a {
color: #ffaa31;
}
.dropdown-menu.follow li:nth-child(2) a {
color: #07beed;
}
.dropdown-menu.follow li:nth-child(3) a {
color: #314d91;
}
.dropdown-menu.follow li:nth-child(4) a {
color: #2d2d2d;
}
.dropdown-menu.follow li:nth-child(5) a {
color: #e84788;
}
.dropdown-menu.follow li:nth-child(1):hover {
background-color: #ffaa31;
}
.dropdown-menu.follow li:nth-child(2):hover {
background-color: #07beed;
}
.dropdown-menu.follow li:nth-child(3):hover {
background-color: #314d91;
}
.dropdown-menu.follow li:nth-child(4):hover {
background-color: #2d2d2d;
}
.dropdown-menu.follow li:nth-child(5):hover {
background-color: #e84788;
}
.dropdown-menu.follow li:hover a {
color: #fff;
margin-left: 10px;
}
.dropdown-menu.share {
width: 120px;
rightright:0;
}
.dropdown-menu.share a {
margin: 10px;
line-height: 26px;
font-size: 12px;
padding-left: 20px;
border: 1px solid #cbcbcb;
border-radius: 2px;
color: #4c4c4c;
background-color: #efefef;
}
.dropdown-menu.share a:hover {
background-color: #fff;
}
.dropdown-menu.share li a:before {
font-size: 12px;
left: 5px;
}
.dropdown-menu.share li:nth-child(1) a:before {
content: “\e04c”;
color: #314d91;
}
.dropdown-menu.share li:nth-child(2) a:before {
content: “\e0a2″;
color: #07beed;
}
.dropdown-menu.share li:nth-child(3) a:before {
content: “\e022″;
color: #2d2d2d;
}
@font-face {
font-family: ‘icomoon’;
src:url(‘fonts/icomoon.eot’);
src:url(‘fonts/icomoon.eot?#iefix’) format(‘embedded-opentype’),
url(‘fonts/icomoon.svg#icomoon’) format(‘svg’),
url(‘fonts/icomoon.woff’) format(‘woff’),
url(‘fonts/icomoon.ttf’) format(‘truetype’);
font-weight: normal;
font-style: normal;
}
到此,關于“怎么用CSS3實現多功能下拉菜單”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。