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 :

Positionnement avec margin /padding


Sujet :

Positionnement en CSS

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2018
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Drôme (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2018
    Messages : 11
    Par défaut Positionnement avec margin /padding
    Bonjour ,

    Je débute en html CSS et je suis confrontait a un problème je souhaite comprendre le fonctionnemd'encapsulation des block et je me retrouve avec une petite incohérence dans ma compréhension.

    Je souhaite obtenir cette image :

    Nom : 15278778014646_attendu.png
Affichages : 228
Taille : 2,6 Ko

    malheureusement j'obtiens une autre version a la fin

    Nom : 15278778144448_reel.png
Affichages : 204
Taille : 3,0 Ko

    Pourriez situer mon erreur et m'aider s'il vous plait je vous pressente mon humble code :

    index.php

    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
    <html>
        <header>
        <link rel="stylesheet" href="style.css" />
        </header>
     
        <body>
            <div id= un >
                <div id= deux>
                    <div id =trois>
                    </div>
                </div>
            </div>
     
            <div id = quatre>
            </div>
     
            <div id =cinq>
            </div>
     
            <div id =six>
            </div>
     
        </body>
     
    </html>

    style.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
    body
    {
        overflow-x: hidden;
        width: 100%;
        height: 100%
    }
     
    #un
    {
        background-color: red;
        width: 100%;
        height: 15%;
    }
     
    #deux
    {
        margin-top: 25%;
        background-color: green;
        width: 100%;
        height: 50%;
    }
     
     
    #trois
    {
        margin-left: 25%;
        background-color: blue;
        width: 50%;
        height: 100%;
    }
     
     
    #quatre
    {
        background-color: pink;
        width: 100%;
        height: 5%;
    }
     
     
    #cinq
    {
        background-color: black;
        width: 100%;
        height: 70%;
    }
     
     
    #six
    {
        background-color: yellow;
        width: 100%;
        height: 10%;
    }

  2. #2
    Expert confirmé
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Haute Savoie (Rhône Alpes)

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

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 132
    Par défaut
    Salut

    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
    <html>
        <header>
        <link rel="stylesheet" href="style.css" />
        </header>
     
        <body>
            <div id="un">
                <div id="deux">
                    <div id="trois">
                    </div>
                </div>
            </div>
     
            <div id="quatre">
            </div>
     
            <div id="cinq">
            </div>
     
            <div id="six">
            </div>
     
        </body>
     
    </html>
    :whistle:pourquoi pas, pour remercier, un :plusser: pour celui/ceux qui vous ont dépannés.
    saut de ligne
    OOOOOOOOO👉 → → Ma page perso sur DVP ← ← 👈

  3. #3
    Membre habitué
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2018
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Drôme (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2018
    Messages : 11
    Par défaut
    @ProgElecT Merci pour ta reponse . J'ai recopier le code aucun changement cela reste comme sur l'image 2 et non la premiere

  4. #4
    Membre extrêmement actif Avatar de psychadelic
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    2 532
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 2 532
    Par défaut
    l'encapsulation des block div en utilisant des % ne marche vraiment qu'avec le modèle Flexbox,
    dans ton cas, si tu veux rester en "classique" :

    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
    48
    49
    50
    51
    52
    53
    54
        html { height: 100%;  }
        * { margin:0; padding: 0; border:0; box-sizing: border-box; }
        body {
          width: 100%;
          height: 100%
        }
        div { display:block;}
        #rouge {
          background-color: red; 
          position:absolute;
          width: 100%;
          height: 15%;
        }
        #vert {
          background-color: green;
          position:relative;
          top:25%;
          left: 0;
          width: 100%;
          height: 50%;
        }
        #bleu {
          background-color: blue;
          position:relative;
          top:0;
          left: 25%;
          width: 50%;
          height: 100%;
        }
        #pink {
          position:absolute;
          top: 15%;
          left:0;
          background-color: pink;
          width: 100%;
          height: 5%;
        }
        #black {
          background-color: black;
          position:absolute;
          top: 20%;
          left:0;
          width: 100%;
          height: 70%;
          color: white;
        }
        #yellow {
          background-color: yellow;
          position:absolute;
          top: 90%;
          left:0;
          width: 100%;
          height: 10%;
        }
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
      <div id="rouge">
        <div id="vert">
          <div id="bleu">
          </div>
        </div>
      </div>
      <div id="pink">
      </div>
      <div id="black">
      </div>
      <div id="yellow">
      </div>

  5. #5
    Membre habitué
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2018
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Drôme (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2018
    Messages : 11
    Par défaut
    @psychadelic merci de tes precission je vais regarder sa de ce pas mais les codes fournis ne marche toujours pas ^^

  6. #6
    Membre extrêmement actif Avatar de psychadelic
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    2 532
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 2 532
    Par défaut
    ?
    relis mieux :
    j'ai changé les ID des DIV en rouge . vert, bleu, etc...

    et j'ai bien sur testé avant de poster

    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
    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
    <!doctype html>
    <html lang="fr">
     
    <head>
      <meta charset="UTF-8">
      <title>blocks couleurs</title>
      <style>
        html {
          height: 100%;
        }
     
        * {
          margin: 0;
          padding: 0;
          border: 0;
          box-sizing: border-box;
        }
     
        body {
          width: 100%;
          height: 100%
        }
     
        div {
          display: block;
        }
     
        #rouge {
          background-color: red;
          position: absolute;
          width: 100%;
          height: 15%;
        }
     
        #vert {
          background-color: green;
          position: relative;
          top: 25%;
          left: 0;
          width: 100%;
          height: 50%;
        }
     
        #bleu {
          background-color: blue;
          position: relative;
          top: 0;
          left: 25%;
          width: 50%;
          height: 100%;
        }
     
        #pink {
          position: absolute;
          top: 15%;
          left: 0;
          background-color: pink;
          width: 100%;
          height: 5%;
        }
     
        #black {
          background-color: black;
          position: absolute;
          top: 20%;
          left: 0;
          width: 100%;
          height: 70%;
          color: white;
        }
     
        #yellow {
          background-color: yellow;
          position: absolute;
          top: 90%;
          left: 0;
          width: 100%;
          height: 10%;
        }
      </style>
    </head>
     
    <body>
     
      <div id="rouge">
        <div id="vert">
          <div id="bleu">
          </div>
        </div>
      </div>
      <div id="pink">
      </div>
      <div id="black">
      </div>
      <div id="yellow">
      </div>
    </body>
     
    </html>

  7. #7
    Rédacteur

    Avatar de danielhagnoul
    Homme Profil pro
    Étudiant perpétuel
    Inscrit en
    Février 2009
    Messages
    6 389
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 75
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant perpétuel
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2009
    Messages : 6 389
    Billets dans le blog
    125
    Par défaut


    Il faut travailler avec un système de mise en page (Flex ou Grid).

    Voici un exemple utilisant Grid et des dimensions en rem.

    Nom : Capture.PNG
Affichages : 180
Taille : 4,3 Ko

    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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    #wrap {
        position: relative;
        width: 40rem;
        height: 3rem;
        display: grid;
        grid-template-columns: 10rem 20rem 10rem;
        grid-template-rows: 1rem 1rem 1rem;
    }
     
    #sup {
        grid-column: 1 / span 3;
        grid-row: 1;
        background-color: red;
        color: white;
        font-size: 50%;
    }
     
    #gauche {
        grid-column: 1;
        grid-row: 2;
        background-color: rgb(83, 146, 83);
        color: white;
        font-size: 50%;
    }
     
    #centre {
        grid-column: 2;
        grid-row: 2;
        background-color: rgb(46, 46, 146);
        color: white;
        font-size: 50%;
    }
     
    #droit {
        grid-column: 3;
        grid-row: 2;
        background-color: rgb(83, 146, 83);
        color: white;
        font-size: 50%;
    }
     
    #inf {
        grid-column: 1 / span 3;
        grid-row: 3;
        background-color: red;
        color: white;
        font-size: 50%;
    }
     
    #principale {
        position: relative;
        background-color: rgb(117, 113, 113);
        width: 40rem;
        height: 10rem;
        color: white;
    }
     
    #pied {
        position: relative;
        background-color: yellow;
        width: 40rem;
        height: 1rem;
        color: black;
        font-size: 50%;
    }

    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <div id="wrap">
        <div id="sup">Supérieure</div>
        <div id="gauche">Gauche</div>
        <div id="centre">Centre</div>
        <div id="droit">Droit</div>
        <div id="inf">Inférieure</div>
    </div>
    <div id="principale">Principale</div>
    <div id="pied">Pied</div>

    Blog

    Sans l'analyse et la conception, la programmation est l'art d'ajouter des bogues à un fichier texte vide.
    (Louis Srygley : Without requirements or design, programming is the art of adding bugs to an empty text file.)

  8. #8
    Membre habitué
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2018
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Drôme (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2018
    Messages : 11
    Par défaut
    Merci pour vos précision ! du cou pour un site qui soit compatible all résolution il vaut mieu utiliser quel unité de mesure ?

  9. #9
    Membre extrêmement actif Avatar de psychadelic
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    2 532
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 2 532
    Par défaut
    Tous les chemins mènent à Rome.

    ( manière polie de dire qu'il n'y a pas de ligne droite, et que les détours éventuels peuvent être aussi riches en apprentissage )

Discussions similaires

  1. [Swing]Gestion du positionnement avec GridBagLayout
    Par yoshï dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 15/04/2006, 21h14
  2. [CSS]Problème de positionnement avec div
    Par Tueur_a_gage dans le forum Mise en page CSS
    Réponses: 11
    Dernier message: 25/10/2005, 23h48
  3. pb positionnement avec float
    Par jerome38000 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 17/08/2005, 19h40

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