A pure CSS off-canvas menu with 2 demos
The off-canvas menu is the one that slides and overlaps the main content with the navigation links.
Generally, you may need to use the JavaScript for creating this type of menu. In this post, an off-canvas menu is shared with pure CSS.
This menu type can particularly be useful for mobile websites where a user may navigate easily to the other sections of the website.
The menu uses font-awesome based icons, so the CSS file of that library is included in the <head> section. You may use some other or design your own icons.
As you bring the mouse over the black bar with icons, the menu will open with navigation links in flying manner. Have a look by clicking the image or link below:
See online demo and code
The CSS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
@import url(http://fonts.googleapis.com/css?family=Raleway:500); body { width: 100%; margin: 0; padding: 0; overflow: hidden; background: #f2f2f3; font-family: 'Raleway', sans-serif; } body h1 { text-align: center; margin-top: 35px; color: #333333; letter-spacing: 1px; text-shadow: 1px 1px #f2f2f3, -1px -1px #f2f2f3; } .css-fly-menu { height: 100%; position: fixed; left: -2em; top: 0; z-index: 1000; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; -webkit-perspective: 1000px; perspective: 1000px; } .menu-icon-style { position: absolute; left: 0; top: 0; z-index: 990; height: 100%; background: #262626; } .menu-icon-style li { border-bottom: 1px solid rgba(0, 0, 0, 0.3); list-style-type: none; } .menu-icon-style a { display: block; width: 64px; height: 64px; line-height: 64px; text-align: center; font-size: 1.6em; color: #999999; text-shadow: 0 1px 0 black; -webkit-transition: all .5s ease-out; transition: all .5s ease-out; } .menu-icon-style a:hover { color: white; -webkit-transform: translateX(10px) scale(1.2); transform: translateX(10px) scale(1.2); } .css-fly-menu:hover .text { -webkit-transform: rotateY(0deg); transform: rotateY(0deg); } .text { position: absolute; left: 63px; top: 0; z-index: 980; height: 100%; background: #262626; border-right: 1px solid rgba(0, 0, 0, 0.3); -webkit-transition: -webkit-transform .24s linear; transition: -webkit-transform .24s linear; transition: transform .24s linear; transition: transform .24s linear, -webkit-transform .24s linear; -webkit-backface-visibility: hidden; backface-visibility: hidden; -webkit-transform-origin: left; transform-origin: left; -webkit-transform: perspective(1000px) rotateY(90deg); transform: perspective(1000px) rotateY(90deg); } .text li { border-bottom: 1px solid rgba(0, 0, 0, 0.3); } .text a { display: block; width: 200px; height: 64px; line-height: 64px; text-indent: 1em; font-size: 1.4em; text-decoration: none; color: #999999; text-shadow: 0 1px 0 black; -webkit-transition: all .5s ease; transition: all .5s ease; } .text a:hover { color: white; -webkit-transform: translateX(-14px); transform: translateX(-14px); } .css-fly-menu:hover .info { left: 0; opacity: 1; -webkit-transition: opacity 0.5s ease-in 0.1s; transition: opacity 0.5s ease-in 0.1s; } .info { position: absolute; padding-left: 2em; bottom: 30px; z-index: 999; width: 264px; color: white; text-align: center; line-height: 1.6; opacity: 0; } .info .logo p { width: 100px; height: 100px; margin: 0 auto; background: #262626; color: #424242; opacity: .6; overflow: hidden; text-align: center; -webkit-transition: all .5s ease; transition: all .5s ease; font-size: 2em; text-shadow: -1px -1px #4f4f4f, 1px 1px #121212; } .info .logo p:hover { opacity: 1; color: white; text-shadow: -1px -1px #575757, 1px 1px #121212; } .info .name { font-size: 2em; font-weight: bold; letter-spacing: 2px; color: #424242; text-shadow: -1px -1px #4f4f4f, 1px 1px #121212; } .info .quote { color: #444; text-shadow: 1px 1px #121212; } .info .social a { font-size: 2em; color: #333333; letter-spacing: .5em; text-shadow: 1px 1px #454545, -1px -1px #121212; -webkit-transition: all .5s ease; transition: all .5s ease; } .info .social a:hover { color: white; text-shadow: -1px -1px #575757, 1px 1px #121212; } @media screen and (max-height: 550px) { .info { display: none; } } @media screen and (max-width: 450px) { h1 { font-size: 7.5vw; } } |
The markup:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<h1>A demo of CSS fly-out off-canvas menu</h1> <div id="nav" class="css-fly-menu"> <div class="menu-icon-style"> <ul> <li><a title="Home" href="#"><i class="fa fa-home "></i></a></li> <li><a href="About"><i class="fa fa-search "></i></a></li> <li><a href="#"><i class="fa fa-edit "></i></a></li> <li><a href="#"><i class="fa fa-cog"></i></a></li> <li><a href="#"><i class="fa fa-code"></i></a></li> <li><a href="#"><i class="fa fa-code"></i></a></li> </ul> </div> <div class="text"> <ul> <li><a title="Home" href="https://www.jquery-az.com/">Home</a></li> <li><a href="https://www.jquery-az.com/?s=" >Search</a> </li> <li><a href="https://www.jquery-az.com/contact/" >Contact</a> </li> <li><a href="https://www.jquery-az.com/css-tutorials/" >CSS</a> <li><a href="https://www.jquery-az.com/html-tutorials/" >HTML</a> <li><a href="https://www.jquery-az.com/jquery-tips/" >jQuery</a> </li> </ul> </div> <div class="info"> <div class="logo"><p>LOGO</p></div> <div class="name">Busniess name</div> <div class="quote">The Slogan of business/company</div> <div class="social"> <a target="_blank" href="https://twitter.com/tmrDevelops"><i class="fa fa-twitter"></i></a> </div> </div> </div> |
Using the same menu as in above demo, in this example, I have played with a few CSS properties for different elements of the menu. For example, the background color is changed along with text color and shadow. The transition is changed to linear from ease value that occurs as you bring the mouse over any item. Have a look:
See online demo and code
The CSS in this demo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
@import url(http://fonts.googleapis.com/css?family=Raleway:500); body { width: 100%; margin: 0; padding: 0; overflow: hidden; background: #f2f2f3; font-family: 'Raleway', sans-serif; } body h1 { text-align: center; margin-top: 35px; color: #333333; letter-spacing: 1px; text-shadow: 1px 1px #f2f2f3, -1px -1px #f2f2f3; } .css-fly-menu { height: 100%; position: fixed; left: -2em; top: 0; z-index: 1000; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; -webkit-perspective: 1000px; perspective: 1000px; } .menu-icon-style { position: absolute; left: 0; top: 0; z-index: 990; height: 100%; background: #408080; } .menu-icon-style li { border-bottom: 1px solid rgba(0, 0, 0, 0.3); list-style-type: none; } .menu-icon-style a { display: block; width: 64px; height: 64px; line-height: 64px; text-align: center; font-size: 1.6em; color: #CB9696; text-shadow: 0 1px 0 black; -webkit-transition: all .5s ease-out; transition: all .5s ease-out; } .menu-icon-style a:hover { color: white; -webkit-transform: translateX(10px) scale(1.2); transform: translateX(10px) scale(1.2); } .css-fly-menu:hover .text { -webkit-transform: rotateY(0deg); transform: rotateY(0deg); } .text { position: absolute; left: 63px; top: 0; z-index: 980; height: 100%; background: #A3D1D1; border-right: 1px solid rgba(0, 0, 0, 0.3); -webkit-transition: -webkit-transform .24s linear; transition: -webkit-transform .24s linear; transition: transform .24s linear; transition: transform .24s linear, -webkit-transform .24s linear; -webkit-backface-visibility: hidden; backface-visibility: hidden; -webkit-transform-origin: left; transform-origin: left; -webkit-transform: perspective(1000px) rotateY(90deg); transform: perspective(1000px) rotateY(90deg); } .text li { border-bottom: 1px solid rgba(0, 0, 0, 0.3); } .text a { display: block; width: 200px; height: 64px; line-height: 64px; text-indent: 1em; font-size: 1.4em; text-decoration: none; color: #408080; text-shadow: 2px 1px 0 #800000; -webkit-transition: all .5s linear; transition: all .5s linear; } .text a:hover { color: white; -webkit-transform: translateY(8px); transform: translateY(8px); } .css-fly-menu:hover .info { left: 0; opacity: 1; -webkit-transition: opacity 0.5s ease-in-out 0.2s; transition: opacity 0.5s ease-in-out 0.2s; } .info { position: absolute; padding-left: 2em; bottom: 30px; z-index: 999; width: 264px; color: white; text-align: center; line-height: 1.6; opacity: 0; } .info .logo p { width: 100px; height: 100px; margin: 0 auto; background: #408080; color: #400000; opacity: .6; overflow: hidden; text-align: center; -webkit-transition: all .5s ease; transition: all .5s ease; font-size: 2em; text-shadow: -1px -1px #4f4f4f, 1px 1px #121212; } .info .logo p:hover { opacity: 1; color: white; text-shadow: -1px -1px #575757, 1px 1px #121212; } .info .name { font-size: 2em; font-weight: bold; letter-spacing: 2px; color: #CB9696; text-shadow: -1px -1px #4f4f4f, 1px 1px #121212; } .info .quote { color: #CB9696; text-shadow: 1px 1px #121212; } .info .social a { font-size: 2em; color: #333333; letter-spacing: .5em; text-shadow: 1px 1px #454545, -1px -1px #121212; -webkit-transition: all .5s ease; transition: all .5s ease; } .info .social a:hover { color: white; text-shadow: -1px -1px #575757, 1px 1px #121212; } @media screen and (max-height: 550px) { .info { display: none; } } @media screen and (max-width: 450px) { h1 { font-size: 7.5vw; } } |
Get the complete code from the demo page.