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 :

Bloc qui dépasse


Sujet :

CSS

  1. #1
    Rédacteur
    Avatar de thierryler
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    4 078
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4 078
    Points : 12 815
    Points
    12 815
    Par défaut Bloc qui dépasse
    Bonjour à tous,

    J'ai un petit soucis de bloc qui ne s'adapte pas à son contenu. Pouvez-vous m'aider ?

    Au niveau du html, j'ai la structure suivante (fichier en pièce jointe) :

    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
    29
    <body id="body">
    	<div id="container">
    		<div id="header">
    			header
    		</div>
     
    		<div id="principal">
    			principal
     
    			<div class="row">
    				<div class="col-6 bloc-A">
    					AAA AAA<br/>
    					AAA AAA<br/>
    					AAA AAA<br/>
    					AAA AAA<br/>
    					AAA
    				</div>
    				<div class="col-6 bloc-B">
    					BBB
    				</div>
    			</div>
     
    		</div>
     
    		<div id="footer">
    			footer
    		</div>
    	</div>
    </body>

    Pour 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
    #body {
    	background: black;
    }
    #container {
    	width: 800px;
    	margin-left: -400px;
    	left: 50%;
    	position: absolute;
    	background: white;
    }
    #header {
    	background: yellow;
    	padding: 10px;
    }
    #principal {
    	background: aqua;
    	padding: 10px;
    }
    #footer {
    	background: orange;
    	padding: 10px;
    }
    div.row {
    	display: block;
    }
    div.col-6 {
    	width: 40%;
    	display: block;
    	float: left;
    }
    div.bloc-A {
    	margin-right: 5px;
    	background: red;
    }
    div.bloc-B {
    	margin-left: 5px;
    	background: blue;
    }
    Comme on le voit (cf. capture), les blocs "AAA" (en rouge) et "BBB" (en bleu), qui font partie du bloc "principal" (en aqua) dépassent du bloc. Ou plutôt, c'est le bloc "principal" qui ne s'adapte pas à son contenu.

    Que dois-je faire ?

    Merci d'avance.
    Thierry
    Images attachées Images attachées  
    Fichiers attachés Fichiers attachés
    Thierry Leriche-Dessirier
    Consultant Java JEE Web Agile freelance
    Rédacteur pour Developpez
    Professeur de Génie Logiciel à l'ESIEA

    Site : http://www.icauda.com / Linked'in : http://www.linkedin.com/in/thierryler / Twitter : @ThierryLeriche

  2. #2
    Membre habitué
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Juillet 2014
    Messages
    92
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Boutique - Magasin

    Informations forums :
    Inscription : Juillet 2014
    Messages : 92
    Points : 152
    Points
    152
    Par défaut
    Salut,

    Tu ne dois plus utiliser des flottants si tu ne veux plus ce comportement. Pour rappel, float fait sortir l'élément du flux, donc le parent ne s'adapte plus en fonction de ses enfants.

    Soit tu utilises des display: inline-block, soit des display: table-cell, soit tu utilises le flexible layout (mais sa compatibilité reste très limitée).

    Quelle compatibilité de navigateur tu souhaites assurer ?

  3. #3
    Rédacteur
    Avatar de thierryler
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    4 078
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4 078
    Points : 12 815
    Points
    12 815
    Par défaut
    Idéalement, je voudrais les navigateurs récents (disons 2 ans).
    Thierry Leriche-Dessirier
    Consultant Java JEE Web Agile freelance
    Rédacteur pour Developpez
    Professeur de Génie Logiciel à l'ESIEA

    Site : http://www.icauda.com / Linked'in : http://www.linkedin.com/in/thierryler / Twitter : @ThierryLeriche

  4. #4
    Membre habitué
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Juillet 2014
    Messages
    92
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Boutique - Magasin

    Informations forums :
    Inscription : Juillet 2014
    Messages : 92
    Points : 152
    Points
    152
    Par défaut
    Le plus simple serait alors de partir sur un display: table-cell en lieu et place des float: left|right à mon avis.

  5. #5
    Rédacteur
    Avatar de thierryler
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    4 078
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4 078
    Points : 12 815
    Points
    12 815
    Par défaut
    Bon je vais abuser un peu. Tu pourrais me donner un exemple de code pour mon cas ?
    Thierry Leriche-Dessirier
    Consultant Java JEE Web Agile freelance
    Rédacteur pour Developpez
    Professeur de Génie Logiciel à l'ESIEA

    Site : http://www.icauda.com / Linked'in : http://www.linkedin.com/in/thierryler / Twitter : @ThierryLeriche

  6. #6
    Invité
    Invité(e)
    Par défaut
    "Ca dépend, ça dépasse !"


  7. #7
    Rédacteur
    Avatar de thierryler
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    4 078
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4 078
    Points : 12 815
    Points
    12 815
    Par défaut
    En utilisant le style suivant, ça prend bien la bonne taille. Mais mes blocs (rouge et bleu) sont maintenant collés, et la ligne n'occupe plus 100% de l'espace dispo :-(

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    div.row {
     
    }
     
    div.col-6 {
    	width: 40%;
    	display: table-cell;
    }
    Images attachées Images attachées  
    Thierry Leriche-Dessirier
    Consultant Java JEE Web Agile freelance
    Rédacteur pour Developpez
    Professeur de Génie Logiciel à l'ESIEA

    Site : http://www.icauda.com / Linked'in : http://www.linkedin.com/in/thierryler / Twitter : @ThierryLeriche

  8. #8
    Membre habitué
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Juillet 2014
    Messages
    92
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Boutique - Magasin

    Informations forums :
    Inscription : Juillet 2014
    Messages : 92
    Points : 152
    Points
    152
    Par défaut
    Voila : http://jsfiddle.net/q82dmayd/


    Code css : 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
    #body {
    	background: black;
    }
     
    #container {
    	width: 800px;
    	margin-left: -400px;
    	left: 50%;
    	position: absolute;
    	background: white;
    }
     
    #header {
    	background: yellow;
    	padding: 10px;
    }
     
    #principal {
    	background: aqua;
    	padding: 10px;
    	display: table;
        width: 100%;
        box-sizing: border-box;
    }
     
    #footer {
    	background: orange;
    	padding: 10px;
    }
     
    div.row {
    	display: table-row;
    }
     
    div.col-6 {
    	width: 50%;
    	display: table-cell;
    }
     
    div.bloc-A {
    	margin-right: 5px;
    	background: red;
    }
    div.bloc-B {
    	margin-left: 5px;
    	background: blue;
    }


    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
    29
    <body id="body">
    	<div id="container">
    		<div id="header">
    			header
    		</div>
     
    		<div id="principal">
    			principal
     
    			<div class="row">
    				<div class="col-6 bloc-A">
    					AAA AAA<br/>
    					AAA AAA<br/>
    					AAA AAA<br/>
    					AAA AAA<br/>
    					AAA
    				</div>
    				<div class="col-6 bloc-B">
    					BBB
    				</div>
    			</div>
     
    		</div>
     
    		<div id="footer">
    			footer
    		</div>
    	</div>
    </body>

  9. #9
    Rédacteur
    Avatar de thierryler
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    4 078
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4 078
    Points : 12 815
    Points
    12 815
    Par défaut
    Magnifique. Merci.

    Je n'ai plus qu'à gérer l'espace entre les colonnes et je serai bon. Mais je crois que j'ai toutes les billes en main pour y arriver.

    Merci à tous
    Thierry Leriche-Dessirier
    Consultant Java JEE Web Agile freelance
    Rédacteur pour Developpez
    Professeur de Génie Logiciel à l'ESIEA

    Site : http://www.icauda.com / Linked'in : http://www.linkedin.com/in/thierryler / Twitter : @ThierryLeriche

  10. #10
    Membre habitué
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Juillet 2014
    Messages
    92
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : Boutique - Magasin

    Informations forums :
    Inscription : Juillet 2014
    Messages : 92
    Points : 152
    Points
    152
    Par défaut
    Pour gérer l'espace entre colonne tu as border-collapse et border-spacing qui sont prévues pour ça.

  11. #11
    Rédacteur
    Avatar de thierryler
    Homme Profil pro
    Inscrit en
    Octobre 2007
    Messages
    4 078
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4 078
    Points : 12 815
    Points
    12 815
    Par défaut
    Tout fonctionne.

    Merci à tous.
    Thierry Leriche-Dessirier
    Consultant Java JEE Web Agile freelance
    Rédacteur pour Developpez
    Professeur de Génie Logiciel à l'ESIEA

    Site : http://www.icauda.com / Linked'in : http://www.linkedin.com/in/thierryler / Twitter : @ThierryLeriche

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

Discussions similaires

  1. Imprimer une form qui dépasse l'écran Scrollbar
    Par TrollTop dans le forum VC++ .NET
    Réponses: 1
    Dernier message: 26/10/2007, 12h49
  2. Tableau qui dépasse de l'écran (barre de défilement nécessaire)
    Par dream_of_australia dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 09/07/2007, 10h05
  3. Image qui dépasse d'un div
    Par vny dans le forum Mise en page CSS
    Réponses: 6
    Dernier message: 09/03/2007, 21h08
  4. Bloc CSS qui dépasse...
    Par Silent dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 19/05/2005, 10h44

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