├── LICENSE ├── README.md ├── css ├── menu.css └── menu.min.css ├── img ├── menu.png ├── search-icon.png └── search-icon.svg └── index.htm /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Matt Smith 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mega Nav in CSS 2 | 3 | A simple mega nav menu in pure CSS. 4 | 5 | 6 | ### Mega Wut? 7 | 8 | Mega navs are an effective feature for large menu content and surprisingly easy to implement. If you've wanted to put one together but didn't know where to start, this quick walkthrough is for you. 9 | 10 | 11 | ### How'd You Do It? 12 | 13 | This implementation uses just CSS and nothing else. After creating a menu list, add `
` to the menu item where the mega nav should display. The following `mega-menu` class will hide the menu: 14 | 15 | ```css 16 | .mega-menu { 17 | background: #fff; 18 | border: 1px solid #ddd; 19 | border-radius: 0 0 3px 3px; 20 | opacity: 0; 21 | position: absolute; 22 | transition: all .3s ease .15s; 23 | visibility: hidden; 24 | width: 100%; 25 | } 26 | ``` 27 | 28 | The mega nav is hidden until you hover over the menu item: 29 | 30 | ```css 31 | li:hover > .mega-menu { 32 | opacity: 1; 33 | overflow: visible; 34 | visibility: visible; 35 | } 36 | ``` 37 | 38 | And voila... 39 | 40 | ![Mega nav image 1](img/menu.png) 41 | 42 | This implementation uses ARIA [landmark roles](http://www.w3.org/TR/wai-aria/roles#landmark_roles) following [WCAG 2.0](http://www.w3.org/TR/WCAG/) compliance for accessibility. Keyboard-only navigation isn't include. 43 | 44 | 45 | ### Support 46 | 47 | Current versions of Chrome, Firefox, Safari, Opera, Edge, and IE8+. 48 | 49 | 50 | ### License 51 | 52 | [The MIT License (MIT)](https://github.com/AllThingsSmitty/mega-nav/blob/master/LICENSE) -------------------------------------------------------------------------------- /css/menu.css: -------------------------------------------------------------------------------- 1 | /* mini reset */ 2 | .nav, 3 | .nav a, 4 | .nav form, 5 | .nav input, 6 | .nav li, 7 | .nav ul { 8 | border: none; 9 | margin: 0; 10 | padding: 0; 11 | } 12 | .nav a { 13 | text-decoration: none; 14 | } 15 | .nav li { 16 | list-style: none; 17 | } 18 | 19 | /* menu container */ 20 | .nav, 21 | input { 22 | font-family: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif; 23 | font-size: 16px; 24 | -webkit-font-smoothing: antialiased; 25 | } 26 | .nav { 27 | cursor: default; 28 | display: inline-block; 29 | position: relative; 30 | z-index: 500; 31 | } 32 | 33 | /* menu list */ 34 | .nav > li { 35 | float: left; 36 | } 37 | 38 | /* menu links */ 39 | .nav > li > a { 40 | background: #372f2b; 41 | border-left: 1px solid #4b4441; 42 | border-right: 1px solid #312a27; 43 | color: #fcfcfc; 44 | display: block; 45 | font-weight: bold; 46 | line-height: 3.5; 47 | padding: 0 1.25em; 48 | position: relative; 49 | text-shadow: 0 0 1px rgba(0, 0, 0, 0.35); 50 | transition: all .3s ease; 51 | z-index: 510; 52 | } 53 | .nav > li > a:focus, 54 | .nav > li:hover > a { 55 | background: #4b4441; 56 | } 57 | .nav > li:first-child > a { 58 | border-left: none; 59 | border-radius: 3px 0 0 3px; 60 | } 61 | 62 | /* search form */ 63 | .nav-search > form { 64 | border-left: 1px solid #4b4441; 65 | height: 3.5em; 66 | position: relative; 67 | width: inherit; 68 | z-index: 510; 69 | } 70 | .nav-search input[type="text"] { 71 | background: #372f2b; 72 | color: #999; 73 | display: block; 74 | float: left; 75 | font-weight: bold; 76 | line-height: 1.5; 77 | padding: 1em 0; 78 | text-shadow: 0 0 1px rgba(0, 0, 0, 0.35); 79 | transition: all .3s ease 1s; 80 | width: 0; 81 | } 82 | .nav-search input[type="text"]:focus { 83 | color: #fcfcfc; 84 | } 85 | .nav-search input[type="text"]:focus, 86 | .nav-search:hover input[type="text"] { 87 | padding: 1em 1.25em; 88 | transition: all .3s ease .1s; 89 | width: 6.875em; 90 | } 91 | .nav-search input[type="submit"] { 92 | background: #372f2b url(../img/search-icon.png) no-repeat center center; /* IE8 fallback */ 93 | background: #372f2b url(../img/search-icon.svg) no-repeat center center; 94 | border-radius: 0 3px 3px 0; 95 | cursor: pointer; 96 | display: block; 97 | float: left; 98 | height: 3.5em; 99 | padding: 0 1.25em; 100 | transition: all .3s ease; 101 | } 102 | .nav-search input:focus, 103 | .nav-search input[type="submit"]:hover { 104 | background-color: #4b4441; 105 | } 106 | 107 | /* menu dropdown */ 108 | .mega-menu { 109 | background: #fff; 110 | border: 1px solid #ddd; 111 | border-radius: 0 0 3px 3px; 112 | opacity: 0; 113 | position: absolute; 114 | transition: all .3s ease .15s; 115 | visibility: hidden; 116 | width: 100%; 117 | } 118 | li:hover > .mega-menu { 119 | opacity: 1; 120 | overflow: visible; 121 | visibility: visible; 122 | } 123 | 124 | /* menu content */ 125 | .nav-column { 126 | float: left; 127 | padding: 2.5%; 128 | width: 20%; 129 | } 130 | .nav-column a { 131 | color: #888; 132 | display: block; 133 | font-weight: bold; 134 | line-height: 1.75; 135 | } 136 | .nav-column a:hover { 137 | color: #2196f3; 138 | } 139 | h3 { 140 | color: #372f2b; 141 | font-size: .95em; 142 | font-weight: bold; 143 | line-height: 1.15; 144 | margin: 1.25em 0 .75em; 145 | text-transform: uppercase; 146 | } 147 | .highlight { 148 | color: #2196f3; 149 | } -------------------------------------------------------------------------------- /css/menu.min.css: -------------------------------------------------------------------------------- 1 | .nav-column a,.nav>li>a,h3{font-weight:700}.nav,.nav a,.nav form,.nav input,.nav li,.nav ul{border:none;margin:0;padding:0}.nav a{text-decoration:none}.nav li{list-style:none}.nav,input{font-family:Roboto,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px;-webkit-font-smoothing:antialiased}.nav{cursor:default;display:inline-block;position:relative;z-index:500}.nav-search>form,.nav>li>a{position:relative;z-index:510}.nav>li{float:left}.nav>li>a{background:#372f2b;border-left:1px solid #4b4441;border-right:1px solid #312a27;color:#fcfcfc;display:block;line-height:3.5;padding:0 1.25em;text-shadow:0 0 1px rgba(0,0,0,.35);transition:all .3s ease}.nav>li:hover>a,.nav>li>a:focus{background:#4b4441}.nav>li:first-child>a{border-left:none;border-radius:3px 0 0 3px}.nav-search>form{border-left:1px solid #4b4441;height:3.5em;width:inherit}.nav-search input[type=text]{background:#372f2b;color:#999;display:block;float:left;font-weight:700;line-height:1.5;padding:1em 0;text-shadow:0 0 1px rgba(0,0,0,.35);transition:all .3s ease 1s;width:0}.nav-search input[type=text]:focus{color:#fcfcfc}.nav-search input[type=text]:focus,.nav-search:hover input[type=text]{padding:1em 1.25em;transition:all .3s ease .1s;width:6.875em}.nav-search input[type=submit]{background:url(../img/search-icon.svg) center center no-repeat #372f2b;border-radius:0 3px 3px 0;cursor:pointer;display:block;float:left;height:3.5em;padding:0 1.25em;transition:all .3s ease}.nav-search input:focus,.nav-search input[type=submit]:hover{background-color:#4b4441}.mega-menu{background:#fff;border:1px solid #ddd;border-radius:0 0 3px 3px;opacity:0;position:absolute;transition:all .3s ease .15s;visibility:hidden;width:100%}li:hover>.mega-menu{opacity:1;overflow:visible;visibility:visible}.nav-column{float:left;padding:2.5%;width:20%}.nav-column a{color:#888;display:block;line-height:1.75}.nav-column a:hover{color:#2196f3}h3{color:#372f2b;font-size:.95em;line-height:1.15;margin:1.25em 0 .75em;text-transform:uppercase}.highlight{color:#2196f3} -------------------------------------------------------------------------------- /img/menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AllThingsSmitty/mega-nav/5150f3cfdd09985d3a77f0d302b20cda34c297ac/img/menu.png -------------------------------------------------------------------------------- /img/search-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AllThingsSmitty/mega-nav/5150f3cfdd09985d3a77f0d302b20cda34c297ac/img/search-icon.png -------------------------------------------------------------------------------- /img/search-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Mega Menu 5 | 6 | 7 | 8 | 9 | 10 | 77 | 78 | --------------------------------------------------------------------------------