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 :

Hauteur Div parent en fonction hauteur Div enfant


Sujet :

Dimensionnement en CSS

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2011
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Septembre 2011
    Messages : 81
    Par défaut Hauteur Div parent en fonction hauteur Div enfant
    Bonjour,

    Je souhaite adapter dynamiquement la hauteur d'un conteneur div (id="about-contact") en fonction de son contenu (class="tabs").
    J'ai tout essayé en CSS et je n'arrive pas à adapter la hauteur de mon conteneur automatiquement. Que ce soit avec un min-height, un height: auto ou d'autres fonctions.

    Je ne sais vraiment pas comment résoudre mon problème. J'ai tenté de résoudre mon problème avec du javascript mais ça n'a rien donné.

    dans mon code html voici ma structure :

    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
    21
    <div id="about-contact" class="box2">
    <div class="tabs">
     <input id="tab-2" type="radio" name="radio-set" class="tab-selector-2" />
    <label for="tab-2" class="tab-label-2">Contact</label>
    <input id="tab-1" type="radio" name="radio-set" class="tab-selector-1" checked="checked" />
    <label for="tab-1" class="tab-label-1">About</label>
     
     
     
    <div class="clear-shadow"></div>
    <div class="content">
     
    <div class="content-1">
    </div>
     
    <div class="content-2">
    </div>
     
    </div>
    </div>
    </div>

    dans mon 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
    #about-contact{
    	background-color: #F5F5F5;
    	position: relative;
    	min-height: 200px;
    	top: 20px;
    	width: 100%;
    	overflow: visible;
    }
    .box2 {
    	position: relative;
    	width: 100%;
    	height: 100%;
    	background-color: #fff;
    	-webkit-box-shadow: 0 1px 5px rgba(0,0,0,0.25);
    	box-shadow: 0 1px 5px rgba(0,0,0,0.25);
    }
    .box2:before {
        position: absolute;
        width: 100%;
        height: 100%;
        border-radius: 10px / 100px;
        z-index: -1;
        top: -5px;
        content: "";
        box-shadow: 0 0 26px rgba(0,0,0,0.51);
    }
     
    .tabs {
    	position: relative;
    	width: 100%;
    	top: -30px;
    	height: auto;
    	min-height: 200px;
    	margin:0; 
    }
     
    .tabs input {
    	position: absolute;
    	z-index: 10;
    	width: 120px;
    	height: 40px;
    	right: 120px;
    	top: 0px;
    	opacity: 0;
        -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
        filter: alpha(opacity=0);
    	cursor: pointer;
    }
    .tabs input#tab-2{
    	right: 0px;
    }
     
     
    .tabs label {
    	background: rgb(85,85,85);
    	font-family: 'confortaa-light';
    	font-size: 14px;
    	line-height: 30px;
    	height: 30px;
    	position: relative;
    	padding: 0 20px;
        float: right;
    	display: block;
    	width: 80px;
    	color: #FFF;
    	text-align: center;
    	text-shadow: 1px 1px 1px rgba(255,255,255,0.3);
        box-shadow: 2px 0 2px rgba(0,0,0,0.1), -2px 0 2px rgba(0,0,0,0.1);
    }
     
    .tabs label:after {
        content: '';
    	position: absolute;
    	bottom: 0px;
    	left: 0;
    	width: 100%;
    	height: 2px;
    	display: block;
    }
     
    .tabs input:hover + label {
    	background: #979797;
    }
     
    .tabs label:first-of-type {
        z-index: 4;
        box-shadow: 2px 0 2px rgba(0,0,0,0.1);
    }
     
    .tab-label-2 {
        z-index: 3;
    }
     
    .tab-label-3 {
        z-index: 2;
    }
     
    .tab-label-4 {
        z-index: 1;
    }
     
    .tabs input:checked + label {
        background: rgb(97,205,245);
    	z-index: 6;
     
    }
     
    .clear-shadow {
    	clear: both;
    }
     
    .content {
    	background: #fff;
    	position: relative;
    	width: 100%;
    	z-index: 5;
    	overflow: visible;
    	border-radius: 0 3px 3px 3px;
     
    }
     
    .content div {
        position: absolute;
    	top: 0;
    	padding-top: 20px;
    	padding-bottom: 20px;
    	padding-left: 70px;
    	padding-right: 70px;
    	z-index: 1;
        opacity: 0;
        -webkit-transition: all linear 0.3s;
        -moz-transition: all linear 0.3s;
        -o-transition: all linear 0.3s;
        -ms-transition: all linear 0.3s;
        transition: all linear 0.3s;
    }
     
    .content-1, .content-3 {
    	-webkit-transform: translateX(-250px);
    	-moz-transform: translateX(-250px);
    	-o-transform: translateX(-250px);
    	-ms-transform: translateX(-250px);
    	transform: translateX(-250px);
    }
     
    .content-2, .content-4 {
        -webkit-transform: translateX(250px);
    	-moz-transform: translateX(250px);
    	-o-transform: translateX(250px);
    	-ms-transform: translateX(250px);
    	transform: translateX(250px);
    }
     
    .tabs input.tab-selector-1:checked ~ .content .content-1,
    .tabs input.tab-selector-2:checked ~ .content .content-2,
    .tabs input.tab-selector-3:checked ~ .content .content-3,
    .tabs input.tab-selector-4:checked ~ .content .content-4 {
    	font-family: 'confortaa-light';
    	font-size: 14px;
        -webkit-transform: translateX(0px);
    	-moz-transform: translateX(0px);
    	-o-transform: translateX(0px);
    	-ms-transform: translateX(0px);
    	transform: translateX(0px);
        -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
        filter: alpha(opacity=100);
        opacity: 1;
        -webkit-transition: all ease-out 0.2s 0.1s;
        -moz-transition: all ease-out 0.2s 0.1s;
        -o-transition: all ease-out 0.2s 0.1s;
        -ms-transition: all ease-out 0.2s 0.1s;
        transition: all ease-out 0.2s 0.1s;
    }
     
    .content div h2,
    .content div h3{
    	font-family: 'confortaa-light';
    	font-size: 20px;
    	color: rgb(85,85,85);
    }
    .content div p {
    	font-family: 'confortaa-light';
    	font-size: 16px;
    	line-height: 22px;
    	font-style: italic;
    	text-align: left;
    	margin: 0;
    	color: #777;
    	padding-left: 15px;
    	font-family: confortaa-light;
    	border-left: 8px solid rgba(63,148,148, 0.1);
    	font-weight: lighter;
    }

  2. #2
    Membre extrêmement actif
    Avatar de Muchos
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    1 704
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Ardennes (Champagne Ardenne)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Décembre 2011
    Messages : 1 704
    Billets dans le blog
    6
    Par défaut
    Je souhaite adapter dynamiquement la hauteur d'un conteneur div (id="about-contact") en fonction de son contenu (class="tabs").
    Il se trouve que c'est le comportement normal. Ex:

    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
    21
    22
    23
    24
    25
    26
    27
    28
     
    <!doctype html>
    <html lang="fr-FR">
    <head>
    	<meta charset="UTF-8" />
    	<title>hauteur adaptable</title>
    	<style type="text/css">
    section {
            margin: 1em 0;
            padding: 1ex;
            background: gray;
    }
    div {
            border: medium solid black;
            background: white;      
    }
            </style>
    </head>
    <body>
    	<section>
    		<div>foo<br>foo<br>foo<br>foo</div>
    	</section>
     
    	<section>
    		<div>bar<br>bar<br>bar<br>bar<br>bar<br>bar<br>bar<br>bar<br></div>
    	</section>
    </body>
    </html>
    Peut-être y'a-t-il une erreur de code, ou un positionnement en absolute qui parasite ce comportement.

  3. #3
    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
    Bonsoir,
    J'ai tout essayé en CSS et je n'arrive pas à adapter la hauteur de mon conteneur automatiquement. Que ce soit avec un min-height, un height: auto ou d'autres fonctions.
    il te suffit simplement de ne pas préciser/fixer de height, le contenant suivra le contenu pour peu que celui ci ne soit pas hors du flux.

Discussions similaires

  1. Comment adapter la hauteur d'une div enfant à une div parent.
    Par infovect dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 06/03/2015, 08h29
  2. DIV parent transparent, mais pas l'enfant. c'est possible ?
    Par nightcyborg dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 16/03/2010, 17h14
  3. Hauteur div parent/enfant et compatibilité IE/FF
    Par Blast Killer dans le forum Mise en page CSS
    Réponses: 5
    Dernier message: 23/01/2009, 08h55
  4. hauteur de div automatique en fonction de l'espace libre
    Par boutmos dans le forum Mise en page CSS
    Réponses: 18
    Dernier message: 30/12/2008, 14h36
  5. [CSS] Créer un style en fonction du div parent
    Par titoumimi dans le forum Mise en page CSS
    Réponses: 1
    Dernier message: 28/02/2006, 09h33

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