IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Mise en page CSS Discussion :

Centrer un menu


Sujet :

Centrer un élément en CSS

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Educateur spécialisé
    Inscrit en
    Janvier 2012
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Educateur spécialisé
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 238
    Par défaut Centrer un menu
    Bonjour à tous et à toutes,
    Je viens vous demander un coup de main pour centrer un menu dans ma page.
    Je cherche depuis deux jours comment faire mais je n'y arrive pas.
    Voici le menu
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?php
    $onglets = array();
    $rubriques = array();
    $sous_onglets = array();
    $req_menu_hor = $bdd->prepare("SELECT id, nom_onglet, lien_onglet, 
    rubrique_id, nom_rubrique, num_id_menu, 
    cor_id_rub, nom_s_ong, lien_s_ong
    ,id_rub_cor, nom_img, lien_img FROM menu 
    LEFT JOIN rubrique_menu ON menu.id = rubrique_menu.num_id_menu 
    LEFT JOIN sous_menu ON rubrique_menu.rubrique_id = sous_menu.cor_id_rub 
    LEFT JOIN image_menu ON rubrique_menu.rubrique_id = image_menu.id_rub_cor 
    WHERE auth_view <= :auth ORDER BY ordre_aff, ordre_rubrique, ordre_s_ong, ordre_aff_img ASC");
    $req_menu_hor->bindValue('auth', $level, PDO::PARAM_INT);
    try {
    		$req_menu_hor->execute();
    		while ($res_menu_hor = $req_menu_hor->fetch())
    			{
    				$tab_menu[$res_menu_hor['nom_onglet']][] = $res_menu_hor;
    			}
    	}
    catch (PDOException $e)
    	{
    	   echo 'Error : ' . $e->getMessage();
    	   die();
    	}
    $req_menu_hor->closeCursor();
    echo'<div class="topnav" id="myTopnav">';
    echo'<span class="logo_menu"><a href="'.VARIABLE[0].'/" title="Accueil de votre opticien à Marseille"><img src="'.VARIABLE[0].'/images/logo-opticien-marseille-le-lunetier.png" alt="Logo de votre opticien Le Lunetier à Marseille"/></a></span>';
    foreach ($tab_menu as $cle_tab_menu => $res_tab_menu)
    	{
    		if($tab_menu[$cle_tab_menu][0]['nom_rubrique'] != '')
    			{
    				echo'<div class="dropdown"><button class="dropbtn">'.$cle_tab_menu.'<i class="fa fa-caret-down"></i> <span class="triangle"></span></button>
    					<div class="dropdown-content">
    						<div class="row">';
    							foreach($res_tab_menu as $cle_rub => $val_rub)
    								{
    									if($rub != $val_rub['nom_rubrique'])
    										{
    											echo'<div class="column">
    												<span class="rubrique_menu">'.$val_rub['nom_rubrique'].'</span>';
    												foreach($res_tab_menu as $cle_so => $val_so)
    													{
    														if($val_so['cor_id_rub'] == $val_rub['rubrique_id'])
    														echo'<a href="'.VARIABLE[0].'/'.$val_so['lien_onglet'].'.'.$val_so['lien_s_ong'].'.html">'.$val_so['nom_s_ong'].'</a>';
    													}
    												if($val_rub['nom_img'] != '')
    													{
    														foreach($res_tab_menu as $cle_img => $val_img)
    															{
    																if($val_img['id_rub_cor'] == $val_rub['rubrique_id'])
    																echo'<a class="image_rub" href="'.$val_img['lien_img'].'" title="'.$val_img['lien_img'].'"><img alt="'.$val_img['lien_img'].'" src="'.VARIABLE[0].'/images/menu/'.$val_img['nom_img'].'"></a>';
    															}
    													}
    											echo'</div>';
    										}
    									$rub = $val_rub['nom_rubrique'];
    								}
    						echo'</div>
    					</div>
    				</div>';
    			}
    		else echo'<a href="'.VARIABLE[0].'/'.$tab_menu[$cle_tab_menu][0]['lien_onglet'].'.html">'.$cle_tab_menu.'</a>';
    	}
    echo'<a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a>
    </div>';
     
    ?>
    Voici le css
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    .logo_menu_gr {display: block;}
    .topnav .logo_menu {display: none;}
    .topnav .icon {display: none;}
    .topnav {
    	max-width:1600px;
    	overflow: hidden;
    	background-color: #fff;
    	font-family: Arial, Helvetica, sans-serif;
    	border-bottom:2px solid #e7e7e7;
    	margin:0 auto;
    	text-align: center;
    	font-variant: small-caps;
    	border:1px solid black;
    }
    .topnav a {
      float: left;
      display: block;
      font-size: 16px;
      color:#555;
      text-align: center;
      padding:20px 16px 0 16px;
      text-decoration: none;
      line-height:50px;
    }
    .topnav .logo_menu a {
      float: left;
      padding:0 16px 0 16px;
      text-decoration: none;
    }
    .topnav .logo_menu a:hover:after {
    	background:none;
    }
    .dropdown {
      float: left;
      display: block;
      overflow: hidden;
    }
    .dropdown .dropbtn {
      font-size: 16px;  
      border: none;
      outline: none;
      color:#555;
      padding:20px 16px 0 16px;
      font: inherit;
      margin: 0;
      line-height:50px;
      background: transparent;
      transition: width .5s ease, background-color .5s ease;
    }
    .topnav a:hover, .dropdown:hover .dropbtn {
      font-weight:700;
    }
    .topnav a:after {
    	content: '';
    	display: block;
    	margin: auto;
    	height: 2px;
    	width: 0;
    	background: transparent;
    	transition: width .5s ease, background-color .5s ease;
    }
    .topnav a:hover:after {
      width:100%;
      background: #000;
    }
    .dropdown .dropbtn:after {
      content: '';
      display: block;
      margin: auto;
      height: 2px;
      width: 0;
      background: transparent;
      transition: width .5s ease, background-color .5s ease;
    }
    .dropdown .dropbtn:hover:after {
      width:100%;
      background: #000;
    }
    .dropdown-content {
      display: none;
      position: absolute;
      background-color: #fff;
      width: 100%;
      left: 0;
      box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
      z-index: 1;
    }
    .dropdown:hover .dropdown-content {
      display: block;
    }
    /* Create three equal columns that floats next to each other */
    .column {
      float: left;
      width: 33.33%;
      padding:10px;
      background-color: #fff;
      height:auto;
    }
    .column a {
      float: none;
      color:#555;
      padding:0 16px;
      text-decoration: none;
      display: block;
      text-align: left;
      margin:0;
      line-height:30px;
    }
    .column a:hover {
      background-color: #e7e7e7;
    }
    .column a:hover:after {
      background:none;
    }
    .column a.image_rub {
    	max-width: 100%;
    	min-height:100px;
    	vertical-align:middle;
    	-moz-transition: all 0.8s;
    	-webkit-transition: all 0.8s;
    	transition: all 0.8s;
    	padding:1% 0;
    }
    .column a.image_rub:hover {
    	-moz-transform: scale(1.10);
    	-webkit-transform: scale(1.10);
    	transform: scale(1.10);
    	background-color:transparent;
    }
    /* Clear floats after the columns */
    .row:after {
      content: "";
      display: table;
      clear: both;
    }
    .rubrique_menu {
    	font-size: 1.5rem;
    	color:#000;
    }
    @media screen and (max-width: 768px) {
    	.column {
    	   width: 100%;
    	   height: auto;
    	}
    	.topnav a:not(:first-child), .dropdown .dropbtn {
    	   display: none;
    	}
    	.topnav a.icon {
    		float: right;
    		display: block;
    	}
    	.topnav .logo_menu a {
    	  float: left;
    	  padding:0 16px 0 16px;
    	  text-decoration: none;
    	}
    	.topnav .logo_menu a:hover:after {
    		background:none;
    	}
    	.logo_menu_gr {display: none;}
    	.topnav .logo_menu {display: block;}
    	.topnav a:hover:after {
    		background:none;
    	}
    	.topnav.responsive {position: relative;}
      .topnav.responsive .icon {
        position: absolute;
        right: 0;
        top: 0;
      }
      .topnav.responsive a {
        float: none;
        display: block;
        text-align: left;
      }
      .topnav.responsive .dropdown {float: none;}
      .topnav.responsive .dropdown-content {position: relative;}
      .topnav.responsive .dropdown .dropbtn {
        display:block;
        width:100%;
    	text-align:left;
    	vertical-align:top;
      }
    .topnav.responsive .dropdown .dropbtn a {
    	display:inline-block;
      }
      .triangle {
    	width:0px;
    	height:0px;
    	display:inline-block;
    	border-left: 5px solid transparent;
    	border-right: 5px solid transparent;
    	border-top: 0;
    	border-bottom: 10px solid #555;
    }
    .dropdown:hover .triangle {
    	width:0px;
    	height:0px;
    	display:inline-block;
    	border-left: 5px solid transparent;
    	border-right: 5px solid transparent;
    	border-bottom: 0;
    	border-top: 10px solid #000;
    }
    }
    et le petit js même si je ne pense pas que ça vienne de là
    Code JavaScript : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    function myFunction() {
      var x = document.getElementById("myTopnav");
      if (x.className === "topnav") {
        x.className += " responsive";
      } else {
        x.className = "topnav";
      }
    }

    Merci d'avance pour votre aide.

  2. #2
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 215
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 215
    Par défaut
    Bonjour,
    ton code serveur ne nous est d'aucune utilité, il faut que tu nous donnes le code HTML généré, Ctrl + U, pour que l'on puisse faire un minimum de test !

  3. #3
    Membre éclairé
    Homme Profil pro
    Educateur spécialisé
    Inscrit en
    Janvier 2012
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Educateur spécialisé
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 238
    Par défaut
    Désolé, je me disais bien.
    Voici
    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <div id="header">
    	<div class="bloc_header_g"></div>
    <div class="bloc_header_c">
    		<span class="logo_menu_gr"><a href="https://sergiocrea.fr/" title="Accueil de votre opticien à Marseille"><img src="https://sergiocrea.fr/images/logo-opticien-marseille-le-lunetier.png" alt="Logo de votre opticien Le Lunetier à Marseille"/></a></span>
    	</div><div class="bloc_header_d"></div></div><div class="topnav" id="myTopnav"><span class="logo_menu"><a href="https://sergiocrea.fr/" title="Accueil de votre opticien à Marseille"><img src="https://sergiocrea.fr/images/logo-opticien-marseille-le-lunetier.png" alt="Logo de votre opticien Le Lunetier à Marseille"/></a></span><a href="https://sergiocrea.fr/accueil.html">Accueil</a><div class="dropdown"><button class="dropbtn">Optiques<i class="fa fa-caret-down"></i> <span class="triangle"></span></button>
    					<div class="dropdown-content">
    						<div class="row"><div class="column">
    												<span class="rubrique_menu">Homme</span><a href="https://sergiocrea.fr/optiques.homme.ray-ban.html">Ray-ban</a></div><div class="column">
    												<span class="rubrique_menu">Femme</span><a href="https://sergiocrea.fr/optiques.femme.ray-ban.html">Ray-ban</a><a href="https://sergiocrea.fr/optiques.femme.persol.html">Persol</a></div><div class="column">
    												<span class="rubrique_menu">Nouveautés</span><a class="image_rub" href="https://sergiocrea.fr/nouveautes-optique.html" title="https://sergiocrea.fr/nouveautes-optique.html"><img alt="https://sergiocrea.fr/nouveautes-optique.html" src="https://sergiocrea.fr/images/menu/Nouveautés-le-lunetier-lunettes-optique-femme.jpeg"></a></div></div>
    					</div>
    				</div><div class="dropdown"><button class="dropbtn">Solaires<i class="fa fa-caret-down"></i> <span class="triangle"></span></button>
    					<div class="dropdown-content">
    						<div class="row"><div class="column">
    												<span class="rubrique_menu">Homme</span><a href="https://sergiocrea.fr/solaires.homme.ray-ban.html">Ray-ban</a></div><div class="column">
    												<span class="rubrique_menu">Femme</span><a href="https://sergiocrea.fr/solaires.femme.ray-ban.html">Ray-ban</a></div><div class="column">
    												<span class="rubrique_menu">Nouveautés</span><a class="image_rub" href="https://sergiocrea.fr/nouveautes-solaire.html" title="https://sergiocrea.fr/nouveautes-solaire.html"><img alt="https://sergiocrea.fr/nouveautes-solaire.html" src="https://sergiocrea.fr/images/menu/Nouveautés-le-lunetier-lunettes-femme-.jpeg"></a></div></div>
    					</div>
    				</div><a href="https://sergiocrea.fr/offres.html">Offres</a><a href="https://sergiocrea.fr/contact.html">Contact</a><a href="https://sergiocrea.fr/a-propos.html">À propos</a><a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()"></a>
    </div>

  4. #4
    Membre Expert
    Avatar de laurentSc
    Homme Profil pro
    Webmaster débutant perpétuel !
    Inscrit en
    Octobre 2006
    Messages
    10 495
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Webmaster débutant perpétuel !
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2006
    Messages : 10 495
    Billets dans le blog
    1
    Par défaut
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <div class="center">
    <!-- ton menu -->
    </div>

    Code css : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    .center{
        margin-left: auto;
        margin-right: auto;
        width: 1000px; /* largeur obligatoire pour être centré */
    }

  5. #5
    Membre éclairé
    Homme Profil pro
    Educateur spécialisé
    Inscrit en
    Janvier 2012
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Educateur spécialisé
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 238
    Par défaut
    Bonjour laurentSc et merci de ton aide.
    C'est ce que j'ai fini par faire, (la largeur obligatoire) mais je l'ai mis directement sur la classe topnav.
    Le souci c'est que si je rajoute des onglets ils font se positionner en dessous des autres et c'est pas top mais pour le moment c'est mieux que rien.

  6. #6
    Membre Expert
    Avatar de laurentSc
    Homme Profil pro
    Webmaster débutant perpétuel !
    Inscrit en
    Octobre 2006
    Messages
    10 495
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Webmaster débutant perpétuel !
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2006
    Messages : 10 495
    Billets dans le blog
    1
    Par défaut
    Désolé, mais même si je connais 2-3 trucs, chu loin de la connaissance de NoSmoking.

    Il est super difficile de s'y retrouver dans le code html avec tous ces div...Par exemple, pas réussi à rajouter des onglets. Comment tu fais ? (je travaille directement sur le html généré). Si tu me l'indiques, je pourrais peut-être trouver le CSS qui va bien pour que ça n'aille pas à la ligne...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. centrer un menu horizontal
    Par philippef dans le forum Mise en page CSS
    Réponses: 1
    Dernier message: 27/08/2007, 12h34
  2. Centrer le menu
    Par Sophie2097 dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 21/02/2007, 14h32
  3. centrer le menu navigation
    Par darcy dans le forum Mise en page CSS
    Réponses: 16
    Dernier message: 14/11/2006, 17h43
  4. [css] Centrer un menu
    Par kilinette dans le forum Mise en page CSS
    Réponses: 4
    Dernier message: 04/06/2005, 16h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo