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 :

Peut-on fixer la hauteur d'un div en %


Sujet :

Dimensionnement en CSS

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Webdesigner
    Inscrit en
    Août 2014
    Messages
    445
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Webdesigner
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Août 2014
    Messages : 445
    Par défaut Peut-on fixer la hauteur d'un div en %
    Bonjour,
    La question a maintes fois été posée sur les forums, mais je n'y ai pas trouvé "ma" réponse
    Mon html est d'un minimaliste extrême :
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <div id="test">
        <div><div>jeny</div></div>
        <div><div></div></div>
        <div><div>arrive</div></div>
        <div><div></div></div>
        <div><div>pas</div></div>
    </div>
    Les div sans texte se voient attribuer une image via les css, div dont je souhaiterais fixer la hauteur en % (les parents ont un height:100%).
    Voici une partie des 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
    body {
      min-height: 100%;
      margin: 0;
      padding: 0;
    }
     
    #test{
    	position: relative;
    	width: 100%;
    	margin: 0px auto;
    	font-size: 0.9em;
    	top: 0px;
    	bottom: 0px;
    	text-align: center;
    	height: 100%;
    }
    #test div{
    	-webkit-perspective: 500px;
    	-moz-perspective: 500px;
    	-ms-perspective: 500px;
    	-o-perspective: 500px;
    	perspective: 500px;
    	-webkit-perspective-origin: 50% 0;
    	-moz-perspective-origin: 50% 0;
    	-ms-perspective-origin: 50% 0;
    	-o-perspective-origin: 50% 0;
    	perspective-origin: 50% 0;
    	width: 100%;
    	margin: 0px auto;
    	height: 100%;
    }
    #test div div{
    	-webkit-animation: rot 1s ease-in-out 1s backwards;
    	-moz-animation: rot 1s ease-in-out 1s backwards;
    	-ms-animation: rot 1s ease-in-out 1s backwards;
    	-o-animation: rot 1s ease-in-out 1s backwards;
    	animation: rot 1s ease-in-out 1s backwards;
    	-webkit-transform-origin: 50% 0;
    	-moz-transform-origin: 50% 0;
    	-ms-transform-origin: 50% 0;
    	-o-transform-origin: 50% 0;
    	transform-origin: 50% 0;
    	font-weight: bold;
    	width: 250px;
    	background: #91eaF3;
    	text-align: center;
    	margin: 0px auto;
    	height: 100%;
    }
     
    #test div:first-child div{
    	/*div avec texte*/
    	font-size: 50px;
    	letter-spacing: -2px;
    	-webkit-animation-delay: 1s;
    	-moz-animation-delay: 1s;
    	-ms-animation-delay: 1s;
    	-o-animation-delay: 1s;
    	animation-delay: 1s;
    }
    #test div:nth-child(2) div{
    	/*div avec image*/
    	-webkit-animation-delay: 2s;
    	-moz-animation-delay: 2s;
    	-ms-animation-delay: 2s;
    	-o-animation-delay: 2s;
    	animation-delay: 2s;
    	background-image: url(kodachrome-40.jpg);
    	background-position: center center;
    	background-size: cover;
    	background-repeat: no-repeat;
    	background-attachment: fixed;
    	width: auto;
    	height: 20%;
    }
    Si cela n'est pas possible, y-a t'il moyen de contourner le problème ?
    Merci pour votre aide et bon week-end,
    dh

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    1/ OUI, sous réserve que TOUS ses parents soient AUSSI dimensionnés en hauteur.
    Or, tu as oublié html :
    Code css : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    html, body {
      height: 100%;
      min-height: 100%;
      margin: 0;
      padding: 0;
    }

    2/ Cible plus précisément les niveaux de div (sinon les propriétés se répercutent sur les enfants, à moins que ce soit voulu) :
    Code css : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    #test > div { ... }
    #test > div > div { ... }
    Dernière modification par Invité ; 07/11/2015 à 16h58.

  3. #3
    Membre éclairé
    Homme Profil pro
    Webdesigner
    Inscrit en
    Août 2014
    Messages
    445
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Webdesigner
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Août 2014
    Messages : 445
    Par défaut
    Bonsoir à toi jreaux62 !!!
    Donc la réponse a bien été donnée dans ce que j'ai vu ailleurs, mais (très) mal appliqué
    Merci pour la correction du code et tes conseils.

    Par contre, maintenant le % s'applique bien aux images, mais mes div font 100% de hauteur.
    Alte-là !!!!!!!!
    Mea Culpa :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    #test > div{height: 20%;}
    (100/5) B.A.BA

    Apparemment, avec mes CSS actuelles, il m'est impossible de fixer une hauteur de 10% au premier div, 30% au second, 20% au troisième...
    Dois-je tout réattaquer à cause d'un parent (ce qui n'est en rien un problème) ?
    Les CSS actuelles :
    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
    html, body {
      height: 100%;
      margin: 0;
      padding: 0;
    }
     
    #test{
    	position: relative;
    	width: 100%;
    	margin: 0px auto;
    	font-size: 0.9em;
    	top: 0px;
    	bottom: 0px;
    	text-align: center;
    	height: 100%;
    }
    #test > div{
    	-webkit-perspective: 500px;
    	-moz-perspective: 500px;
    	-ms-perspective: 500px;
    	-o-perspective: 500px;
    	perspective: 500px;
    	-webkit-perspective-origin: 50% 0;
    	-moz-perspective-origin: 50% 0;
    	-ms-perspective-origin: 50% 0;
    	-o-perspective-origin: 50% 0;
    	perspective-origin: 50% 0;
    	width: 100%;
    	margin: 0px auto;
    	height: 20%;
    }
    #test > div > div{
    	-webkit-animation: rot 1s ease-in-out 1s backwards;
    	-moz-animation: rot 1s ease-in-out 1s backwards;
    	-ms-animation: rot 1s ease-in-out 1s backwards;
    	-o-animation: rot 1s ease-in-out 1s backwards;
    	animation: rot 1s ease-in-out 1s backwards;
    	-webkit-transform-origin: 50% 0;
    	-moz-transform-origin: 50% 0;
    	-ms-transform-origin: 50% 0;
    	-o-transform-origin: 50% 0;
    	transform-origin: 50% 0;
    	font-weight: bold;
    	width: 250px;
    	background: #91eaF3;
    	text-align: center;
    	margin: 0px auto;
    	height: 100%;
    }
     
    #test > div:first-child div{
    	/*div avec texte*/
    	font-size: 50px;
    	letter-spacing: -2px;
    	-webkit-animation-delay: 1s;
    	-moz-animation-delay: 1s;
    	-ms-animation-delay: 1s;
    	-o-animation-delay: 1s;
    	animation-delay: 1s;
    }
    Merci et bonne fin de week-end
    dh

  4. #4
    Invité
    Invité(e)
    Par défaut
    il m'est impossible de fixer une hauteur de 10% au premier div, 30% au second, 20% au troisième...
    Si, avec :nth-child(...)
    ou en ajoutant des class.

  5. #5
    Membre éclairé
    Homme Profil pro
    Webdesigner
    Inscrit en
    Août 2014
    Messages
    445
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Webdesigner
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Août 2014
    Messages : 445
    Par défaut
    OF COURSE !!!
    A me noyer dans les CSS de base, j'en ai oublié les classes
    J'ai honte
    Bonne soirée/week-end et encore merci à toi
    dh

  6. #6
    Invité
    Invité(e)
    Par défaut
    Va t'aérer la tête, et profiter du week-end

    "Trop de code tue le code..."

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

Discussions similaires

  1. Fixer la hauteur d'un div
    Par okoweb dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 23/07/2013, 15h35
  2. Fixer la hauteur d'un div
    Par Core8 dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 28/07/2007, 12h24
  3. changer la hauteur d'un Div
    Par MASSAKA dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 14/09/2005, 11h05
  4. Recuperer la hauteur d'une DIV
    Par rol666 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 26/08/2005, 14h01

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