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
| <!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content=" ">
<title>Menu viacable</title>
<!-- d'après le code de Jreaux62 du forum css www.developpez.net -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<style>
/*==========================================================================================================*/
/*============ Définitions de départ ====================*/
/*==========================================================================================================*/
* {
margin: 0; /* Mettons TOUTES les marges extérieures à zéro */
padding: 0; /* Mettons TOUS les espaces intérieures à zéro */
border:0;
box-sizing: border-box; /* largeur des boites= width+padding+border */
}
html, body {
height: 100%; /* Toute la hauteur de l'écran */
font-size: 100%; /* 100%=16px=1rem */
}
body {
font-family: "Times New Roman", Times, serif; /* Définition des polices de base */
font-size: 100%; /* 100%=16px=1em */
}
#page {
position: relative;
}
#page {
height:350px;
border:1px solid red;
}
/*==========================================================================================================*/
/*============ Définitions du menu de navigation navmain ====================*/
/*==========================================================================================================*/
nav#navMain {
position: relative;
width: 40vw;
height: auto;
margin: 0 auto;
padding:0;
font-style: italic;
font-size: 90%;
}
#navMain ul {
list-style-type: none;
opacity: 0.92;
}
#navMain ul li {
position:relative;
min-width: 170px;
padding: 1px;
}
#navMain a {
height:30px;
display: block;
padding: 5px 0;
font-weight: bold;
text-align: center;
background: #031c4b;
color: #fff;
text-decoration: none;
}
#navMain li:hover a {
text-decoration: underline;
}
#navMain > ul > li:hover > a {
background: #001847;
color:#fff;
}
#navMain ul ul > li a {
background: #333;
color:#fff;
}
#navMain ul ul > li:hover a {
background: #7b7b7b;
}
#navMain li:hover > a {
text-decoration: underline;
}
#navMain li.hasSub > ul {
display: none;
}
/* ------------------------------- */
/* fleche, avec rotation */
#navMain .hasSub:after {
position: absolute;
content: '\25BC';
display: block;
font-size: 0.7em;
color: #fff;
top: 14px;
right: 6px;
cursor: pointer;
-webkit-transform: rotate(0deg);
-webkit-transition: -webkit-transform 0.5s;
transform: rotate(0deg);
transition: transform 0.5s;
}
#navMain .hasSub.open:after {
-webkit-transform: rotate(180deg);
-webkit-transition: -webkit-transform 0.5s;
transform: rotate(180deg);
transition: transform 0.5s;
}
/* TEST : menu full vertical */
#navMain {
max-width: 960px;
}
/*============== décoration ===============*/
#navMain a {
border:1px solid black;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
-moz-box-shadow: 5px 5px 2px 0px #666;
-webkit-box-shadow: 5px 5px 2px 0px #666;
box-shadow: 5px 5px 2px 0px #666;
}
#navMain > ul li {
padding:1px 0 0 0;
}
/*==========================================================================================================*/
/* Définition pour Smartphone */
/* Smartphone ---> 740px, 720px, 480px et 320px */
/*==========================================================================================================*/
@media screen and (max-width:740px) {
}
/*==========================================================================================================*/
/* Définition pour Tablette et Desktop */
/* Tablette ---> 740px et 1024px */
/* Desktop ---> 1024px et 1600px */
/*==========================================================================================================*/
@media screen and (min-width:741px) {
#page,
#page > nav#navMain {
width:960px;
margin:0 auto;
}
#page {
height:350px;
border:1px solid red;
}
nav#navMain {
position: fixed;
top: 200px;
right: 0;
left: 0;
z-index: 1;
order:0; /* on remet la navigation après le bandeau */
}
#navMain > ul {
display: -webkit-flex;
display: flex;
}
#navMain > ul > li {
-webkit-flex: 1 1 10%;
flex: 1 1 10%;
}
#navMain > ul > li > ul {
position: absolute;
width: 100%;
z-index: 1;
}
}
</style>
</head>
<body>
<div id="page">
<nav id="navMain">
<ul>
<li><a href="#">Accueil</a></li>
<li><a href="#">Informatique</a>
<ul>
<li><a href="#">Calendrier</a>
<ul>
<li><a href="#"> Décembre 2017</a></li>
<li><a href="#">Janvier 2018</a></li>
<li><a href="#">Février 2018</a></li>
<li><a href="#">Mars 2018</a></li>
</ul>
</li>
<li><a href="#">Tutoriel</a></li>
<li><a href="#">Documentation</a></li>
<li><a href="#">Exercices</a></li>
<li><a href="#">Corrigés</a></li>
<li><a href="#">Outils</a></li>
</ul>
</li>
<li><a href="#">Photographie</a></li>
<li><a href="#">Cinéma</a>
<ul>
<li><a href="#">Niveau 2</a>
<ul>
<li><a href="#">Niveau 2.1</a></li>
<li><a href="#">Niveau 2.2</a></li>
<li><a href="#">Niveau 2.3</a></li>
<li><a href="#">Niveau 2.4</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Nous contacter</a> </li>
</ul>
</nav>
</div>
<script type="text/javascript">
// ------------------------------------------------
// jquery.dropdown.js (depends on: jquery.hoverIntent.js)
// ------------------------------------------------
$.fn.dropdown = function(options) {
var defaults = {};
var opts = $.extend(defaults, options);
// Apply class=hasSub on those items with children
this.each(function() {
$(this)
.find("li")
.each(function() {
if ($(this).find("ul").length > 0) {
$(this).addClass("hasSub");
}
});
});
return this;
};
// ------------------------------------------------
// MENU MAIN
$(function() {
var navMainId = "#navMain";
// -------------------
// Calling the jquery dropdown
$(navMainId).dropdown();
// -------------------
//Sous-Menu ouvert par defaut
$(navMainId + " ul > li.active").addClass("open");
$(navMainId + " ul > li.active > ul").slideDown("fast");
// -------------------
// ouverture/fermeture sous-menu (click/touch)
$(navMainId + " ul > li").on("click", function(event) {
event.stopPropagation(); /* important */
$(this)
.parent()
.find("li:not(:hover)")
.removeClass("open");
$(this).toggleClass("open");
$(this)
.parent()
.find("li:not(:hover) ul")
.slideUp("fast");
if ($(this).hasClass("hasSub")) {
$(this)
.children("ul")
.slideToggle("fast");
}
});
// -------------------
// on désactive les liens des Menus AVEC Sous-Menus (obligatoire pour Tablettes TACTILES / Smartphones)
$(navMainId + " > ul > li.hasSub > a").on("click", function(event) {
event.preventDefault();
});
// -------------------
});
// ------------------------------------------------
// Scrollbar si menu plus grand que la hauteur de fenêtre
$(window).on("load resize", function() {
var navMainId = "#navMain";
// $(navMainId).height( Math.min( $(window).height(), $(navMainId).height() ) ); // A ADAPTER par rapport à la hauteur effectivement disponible : hors header, footer,....
// $(navMainId).css({ "overflow-y": "auto" });
});
// ------------------------------------------------
</script>
</body>
</html> |
Partager