Раздвижное меню Аккордеон с плавным эффектом

Если вы видите скриншот или уже посмотрели демо, то вы наверняка обратили свой взгляд на то, что картинки(иконки меню) все ровно присутствуют. Все эти картинки созданы при помощи технологии data:image. Подробней о этой технологии вы можете погуглить! И так начнем.

HTML

Пишем нашу разметку

Код
<nav class="list-wrap">
  <ul class="list list--margin">
  <li class="list-item">
  <i class="icon--home"></i>
  <a href="#" class="list-link">Главаня</a><span class="list-notice">3</span>
  </li>

  <li class="list-item list-item--corner">
  <i class="icon--gallery"></i><a href="#" class="list-link">Галерея</a>
  <ul class="list list--sub">
  <li class="list-item"><i class="icon--corner"></i><a href="#" class="list-link">Фотографии</a></li>
  <li class="list-item"><i class="icon--corner"></i><a href="#" class="list-link">Фотографии</a></li>
  <li class="list-item"><i class="icon--corner"></i><a href="#" class="list-link">Фотографии</a></li>
  </ul>
  </li>

  <li class="list-item">
  <i class="icon--logout"></i><a href="#" class="list-link">Logout</a>
  </li>
  </ul>
  </nav>

Тег <i> используется здесь для вставки наших иконок в те места где они нужно, каждой иконке присвоен свой класс.

И теперь CSS

Для преобразования картинок в формат data:image я использовал онлайн генератор image2base64.wemakesites.net 

Код
i[class^="icon--"] {width:18px; display:inline-block; vertical-align:middle; font-size:0; background-repeat:no-repeat; background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAA7CAYAAAATgCjWAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRm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BSL7XxISICuZkVba/m165UXor/afKKm5loL+zvIHUtHesaMWcCe0uqPg2l2xWlYIHQvfuIk4cIZ4sTmMAHblwyogY3o2k56fHz8GcWVlVe7aMy9WMG8A7PjPg5h/zMXj+QqZbuSY+6AEiZmhOyXOH/TRVnKwnpAf/fVLSCtVvu3A+J6eHrT7e3t7O8ZVoYX1deruMgzZpGOHiHj/lU+1MlCyMKdtrg6rcUpG8X8cv1XWIgFY2dh8/fAkkOTU7C/AtD/BRgAbw3HGHxxLJYAAAAASUVORK5CYII=');}
  .icon--home {background-position:0 0; height:17px;}
  .icon--gallery {background-position:0 -17px; height:17px;}
  .icon--logout {background-position:0 -34px; height:18px;}
  .icon--corner {background-position:0 -52px; height:7px; width:7px !important;}

.list--margin {margin:60px auto;}

.list {list-style:none; color:#d9ddea; text-shadow:1px 1px 0px #383a42;}
.list .list-item {border-top:1px solid #1e2028; line-height:40px; position:relative;}
.list .list-item .list-link {color:#d9ddea; text-decoration:none; display:block; position:relative; margin:-40px 0 0 0;}
.list .list-item i[class^="icon--"] {margin-left:11px;}
.list .list-item .icon--corner {margin-left:17px !important;}

.list .list-item:hover > .icon--home {background-position:-18px 0;}
.list .list-item:hover > .icon--gallery {background-position:-18px -17px;}
.list .list-item:hover > .icon--logout {background-position:-18px -34px;}
.list .list-item:hover > .icon--corner {background-position:-7px -52px;}

.list .list-item:hover .list--sub {max-height:120px;}

.list-wrap > .list {border:1px solid #1e2028; width:198px; border-radius:3px; box-shadow:0px 0px 5px rgba(0,0,0,.15);}
.list-wrap > .list > .list-item:first-child {border:0; border-radius:2px 2px 0 0;}
.list-wrap > .list > .list-item:last-child {border-radius:0 0 2px 2px;}
.list-wrap > .list > .list-item {background:#454851; box-shadow:inset 1px 1px 0 rgba(255,255,255,.1); background:-webkit-linear-gradient(top, #494b53, #414248); background:-moz-linear-gradient(top, #494b53, #414248); background:-o-linear-gradient(top, #494b53, #414248); background:-ms-linear-gradient(top, #494b53, #414248); background:linear-gradient(top, #494b53, #414248);}
.list-wrap > .list > .list-item > .list-link {padding:0 0 0 39px;}

  .list--sub {max-height:0; overflow:hidden; -webkit-transition:all .5s ease; -moz-transition:all .5s ease; -o-transition:all .5s ease; transition:all .5s ease;}
  .list--sub .list-item {line-height:39px; background:#33353b; background:-webkit-linear-gradient(top, #30343f, #2b2e38); background:-moz-linear-gradient(top, #30343f, #2b2e38); background:-o-linear-gradient(top, #30343f, #2b2e38); background:-ms-linear-gradient(top, #30343f, #2b2e38); background:linear-gradient(top, #30343f, #2b2e38);}
  .list--sub .list-item .list-link {padding:0 0 0 40px;}

  .list--sub .list-item:hover {box-shadow:inset 1px 1px 0 rgba(255,255,255,.1); background:#3355ca; background:-webkit-linear-gradient(top, #4554ce, #3941c0); background:-moz-linear-gradient(top, #4554ce, #3941c0); background:-o-linear-gradient(top, #4554ce, #3941c0); background:-ms-linear-gradient(top, #4554ce, #3941c0); background:linear-gradient(top, #4554ce, #3941c0);}
  .list--sub .list-item:first-child {box-shadow:inset 0 2px 1px -1px rgba(0,0,0,.4);}
  .list--sub .list-item:last-child {box-shadow:inset 0 -2px 1px -1px rgba(0,0,0,.4);}

.list .list-item--corner > .list-link:after {content:''; position:absolute; width:0; height:0; border:5px solid transparent; border-top-color:#2a2b30; top:50%; right:14px; margin:-2px 0 0 0;}
.list .list-item--corner > .list-link:before {content:''; position:absolute; width:0; height:0; border:5px solid transparent; border-top-color:#4e5059; top:50%; right:13px; margin:-1px 0 0 0;}

.list .list-notice {position:absolute; display:block; height:100%; top:0; right:14px; padding-right:11px;}
.list .list-notice:after {content:''; background:#d53e3e; border-radius:50%; width:5px; height:5px; display:block; position:absolute; top:50%; right:0px; margin-top:-2px; box-shadow:0 0 1px 1px #3b2e33; background:-webkit-linear-gradient(top, #f29495, #e93738); background:-moz-linear-gradient(top, #f29495, #e93738); background:-o-linear-gradient(top, #f29495, #e93738); background:-ms-linear-gradient(top, #f29495, #e93738); background:linear-gradient(top, #f29495, #e93738);}

  • FalleN

  • 9934

  • 1

  • 300

Ссылки на статью:

Похожие статьи: