28172 sujets

CSS et mise en forme, CSS3

Bonjour à vous,

j'aimerais bien avoir un menu du coté gauche et le corps du site du côté droit.

Quand je diminue ou agrandis la fenêtre, j'aimerais bien que le menu reste pareil et que le texte soit automatique redimensionné afin qu'il ne se retrouve pas en-dessous du logo de l'élément du menu. Pareil pour le corps du site.

Quelle technique puis-je utiliser pour faire cela ?

Merci d'avance

Bon dimanche

Thierry
Bonjour yiujia,

tout d'abord, merci pour votre réponse à ma question.

En effet, c'est un truc de ce genre que je cherche à faire.

Si vous voulez, voici la solution sur laquelle j'étais parti mais je pense que je n'ai pas pris la solution la plus facile.



<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0">
        <title>Menu</title>
    </head>
    <body>
        <div class="site-container">
                <header class="header">
                    <a href="#" class="header__icon" id="header__icon"></a>
                    <a href="#" class="header__logo">Logo</a>
                </header>
                <div class="site-content">
                    <nav class="menu">
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu1</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu2</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu3</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu4</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu5</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu6</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu7</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu8</a>
                    </nav>
                    <div class="container">
                        <h1 id="firstHeading" class="firstHeading" lang="en">Amazon Women in the Mood</h1>
                        <h2><span class="mw-headline" id="Plot">Plot</span></h2>
                        <p><a href="/wiki/Amy_Wong" title="Amy Wong">Amy</a> has been receiving phone calls for a year, where the caller stammers and then hangs up. The calls are from <a href="/wiki/List_of_recurring_Futurama_characters#Kif_Kroker" title="List of recurring Futurama characters">Kif</a>, who is in love with Amy but is too nervous to speak. <a href="/wiki/Zapp_Brannigan" title="Zapp Brannigan">Zapp</a> realizes that Amy and <a href="/wiki/Leela_(Futurama)" title="Leela (Futurama)">Leela</a> know each other, and asks the two of them to go on a <a href="/wiki/Dating" title="Dating">double date</a> with him and Kif. Leela agrees as a favor to Amy, and they go to a restaurant aboard a space liner.
                        </p><p>Kif uses Zapp's characteristically boorish pick-up lines, offending Amy. To prevent her and Leela from leaving, Kif sings <a href="/wiki/Karaoke" title="Karaoke">karaoke</a>. Amy is touched by this, but Zapp pushes Kif off the stage and <a href="/wiki/William_Shatner%27s_musical_career#After_The_Transformed_Man" title="William Shatner&#39;s musical career">sings to Leela</a>, causing the passengers and crew of the ship to flee the restaurant in terror. Zapp crashes the ship into the planet Amazonia, where the Amazonians, a race of giant, muscular, tribal women, capture them.
                    </p><p><a href="/wiki/Philip_J._Fry" title="Philip J. Fry">Fry</a> and <a href="/wiki/Bender_(Futurama)" title="Bender (Futurama)">Bender</a> travel to Amazonia to rescue their friends but are also captured. They are taken to the Amazonians' leader, observing Amazonian society along the way. Fry, Zapp, and Bender ridicule female values, which makes Leela and Amy appreciate how good life would be without men. When the Amazonians ask what the purpose of men is, Amy explains, and the Amazonians realize that what she is describing is <a href="/wiki/Sexual_intercourse" title="Sexual intercourse">snu-snu</a>, something they have heard of, but never experienced.
                      </p>
                        
                    </div>
                </div>
        </div>
    </body>
</html>



html, body {
  font-family: Roboto;
  font-size: 16px;
  line-height: 1.4;
  height: 100%;
  margin: 0;
  padding: 0;
}
a {
  text-decoration: none;
  color: inherit;
}
.container {
  position: relative;
  left: 220px;
  float: left;
  margin: 0 5px;
  width: 84%;
}
.site-content {
  padding-top: 55px;
  background-color: #f2f2f2;
}
.header {
  position: fixed;
  z-index: 1;
  left: 0;
  right: 0;
  height: 55px;
  line-height: 55px;
  color: #FFF;
  background-color: #222A35;
}
.header__logo {
  font-weight: bold;
  padding: 0 25px;
  float: left;
}

  .menu {
    float: left;
    position: fixed;
    padding-top: 25px;
    left: 0;
    top: 55px;
    bottom: 0;
    background-color: #f2f2f2;
    width: 15%;
    z-index: 10;
  }
  .menu a {
    display: block;
    height: 45px;
    text-align: left;
    line-height: 45px;
    color: #757575;
    font-size: 15px;
    font-weight: bold;
  }

  /* line 97, ../sass/_responsive.scss */
  .menu img {
    float: left;
    padding: 10px 20px 0 12px;
  }


Je pense que ce serait nettement plus simple si j'utilisais un système de grilles ou les flex.

Le seul souci, c'est que pour la version laptop, c'est assez simple. Par contre, il y a entre autre le menu qui disparaît pour la version smartphone et qui apparaît quand l'utisateur scroll ou appuie sur l'icône pour le faire apparaître.

Bon dimanche à vous,
Thierry
Bonjour yiujia,

encore une fois, je tenais à vous remercier pour votre réponse à mon message.

Cependant, j'aurai encore une question à vous poser.

En fait, par rapport au code que je vous ai envoyé en fonction de ce que j'ai déjà pu développer, je me demandais comment faire pour éviter d'avoir une scroll bar horizontale et faire en sorte que le texte descende automatique quand on diminue la fenêtre ou que le texte remonte quand on agrandit la fenêtre.

Merci d'avance

Bon dimanche.

Thierry
Bonjour,

à partir de ton code, changes le css avec ça :

.container {
  position: relative;
  /*left: 220px;
  float: left;*/
  margin: 0 5px;
  margin-left: 15%;
  /*width: 84%;*/
}
Bonjour yiujia,

une fois de plus, je tenais à vous remercier pour votre aide.

Cependant, malheureusement, ça ne donne pas le résultat escompté.

SI cela ne vous dérange pas, je vais donc remettre le code.


<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0">
        <title>Menu</title>
    </head>
    <body>
        <div class="site-container">
            <div class="site-pusher">
                <header class="header">
                    <a href="#" class="header__icon" id="header__icon"></a>
                    <a href="#" class="header__logo">Logo</a>
                </header>
                <div class="site-content">
                    <nav class="menu">
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu 1</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu 2</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu 3</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu 4</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu 5</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu 6</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu 7</a>
                        <a href="#"><img src="public/img/menu_arrow" width="25" height="25" class="menu_icon"/>Menu 8</a>
                    </nav>
                    <div class="container">
                        <h1 id="firstHeading" class="firstHeading" lang="en">Amazon Women in the Mood</h1>
                        <h2><span class="mw-headline" id="Plot">Plot</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Amazon_Women_in_the_Mood&amp;action=edit&amp;section=1" title="Edit section: Plot">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
                        <p><a href="/wiki/Amy_Wong" title="Amy Wong">Amy</a> has been receiving phone calls for a year, where the caller stammers and then hangs up. The calls are from <a href="/wiki/List_of_recurring_Futurama_characters#Kif_Kroker" title="List of recurring Futurama characters">Kif</a>, who is in love with Amy but is too nervous to speak. <a href="/wiki/Zapp_Brannigan" title="Zapp Brannigan">Zapp</a> realizes that Amy and <a href="/wiki/Leela_(Futurama)" title="Leela (Futurama)">Leela</a> know each other, and asks the two of them to go on a <a href="/wiki/Dating" title="Dating">double date</a> with him and Kif. Leela agrees as a favor to Amy, and they go to a restaurant aboard a space liner.
                        </p><p>Kif uses Zapp's characteristically boorish pick-up lines, offending Amy. To prevent her and Leela from leaving, Kif sings <a href="/wiki/Karaoke" title="Karaoke">karaoke</a>. Amy is touched by this, but Zapp pushes Kif off the stage and <a href="/wiki/William_Shatner%27s_musical_career#After_The_Transformed_Man" title="William Shatner&#39;s musical career">sings to Leela</a>, causing the passengers and crew of the ship to flee the restaurant in terror. Zapp crashes the ship into the planet Amazonia, where the Amazonians, a race of giant, muscular, tribal women, capture them.
                    </p><p><a href="/wiki/Philip_J._Fry" title="Philip J. Fry">Fry</a> and <a href="/wiki/Bender_(Futurama)" title="Bender (Futurama)">Bender</a> travel to Amazonia to rescue their friends but are also captured. They are taken to the Amazonians' leader, observing Amazonian society along the way. Fry, Zapp, and Bender ridicule female values, which makes Leela and Amy appreciate how good life would be without men. When the Amazonians ask what the purpose of men is, Amy explains, and the Amazonians realize that what she is describing is <a href="/wiki/Sexual_intercourse" title="Sexual intercourse">snu-snu</a>, something they have heard of, but never experienced.
                    </p><p>The leader of the Amazonians is the Femputer, a giant computer (voiced by <a href="/wiki/Bea_Arthur" title="Bea Arthur">Bea Arthur</a>). Bender is spared for not possessing <a href="/wiki/Sex_organ" title="Sex organ">male anatomy</a>, but Zapp, Fry, and Kif are sentenced by the Femputer to death by snu-snu&#160;— a fate that both excites and horrifies them&#160;— and are repeatedly snu-snued by Amazonians. Before being taken away Kif tells Amy that he was the one who kept calling her and hanging up, that the offensive pick-up lines were not his own words, and that he loves her. Amy resolves to save him.
                    </p><p>Leela and Amy convince Bender to reprogram the Femputer. He discovers that the Femputer is actually a computer operated by a <a href="/wiki/Gynoid" title="Gynoid">fembot</a>, who created the Amazonian society because her home planet was extremely chauvinistic. Amy rescues Kif; the Amazonians chase after them, cornering them in the Femputer's chamber. By this time, however, Bender and the fembot have become romantic. They order the Amazonians to release their captives and bring gold.
                    </p><p>The crew returns to Earth where Fry and Zapp receive treatment for their crushed pelvises. Bender has a pile of gold bricks, and Kif and Amy are a couple. They all agree that Amazonia was their best mission ever.
                    </p>
                    </div>
                    <div class="site-cache" id="site-cache">
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>



html, body {
  font-family: Roboto;
  font-size: 16px;
  line-height: 1.4;
  height: 100%;
  margin: 0;
  padding: 0;
}

a {
  text-decoration: none;
  color: inherit;
}

.container {
  padding: 0 20px;
  overflow: hidden;
  *zoom: 1;
  background-color: #f2f2f2;
}

.site-content {
  padding-top: 55px;
  background-color: #f2f2f2;
}

/* $HEADER */
.header {
  position: fixed;
  left: 0;
  right: 0;
  height: 55px;
  line-height: 55px;
  color: #FFF;
  background-color: #222A35;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  z-index: 10;
}

.header__logo {
  font-weight: bold;
  padding: 0 25px;
  float: left;
}

/* $MENU */
.menu a {
  padding: 0 10px;
}

.menu a:hover {
  color: #222A35;
}

  .container {
    position: relative;
    left: 235px;
    float: left;
    width: 100%;
    background-color: #f2f2f2;
  }

  .menu {
    float: left;
    position: fixed;
    padding-top: 25px;
    left: 0;
    top: 55px;
    bottom: 0;
    background-color: #f2f2f2;
    width: 235px;
    z-index: 1;
  }

  .menu a {
    display: block;
    height: 45px;
    text-align: left;
    line-height: 45px;
    color: #757575;
    font-size: 15px;
    font-weight: bold;
  }

  .menu img {
    float: left;
    padding: 10px 20px 0 12px;
  }


Merci d'avance pour votre aide.

Thierry

P.S. : si vous soyez des incohérences dans le code, n'hésitez surtout pas à me le signaler.
En fait, tu mets un margin-left égale au width de ton menu

.container {
    position: relative;
    /*left: 235px;
    float: left;
    width: 100%;*/
    margin-left: 235px;
    background-color: #f2f2f2;
  }


Conseil pour un code css lisible et facile à maintenir, évites d'avoir du css sur un élément à plusieurs endroits.
Exemple :

.menu a {
  padding: 0 10px;
}

  .menu a {
    display: block;
    height: 45px;
    text-align: left;
    line-height: 45px;
    color: #757575;
    font-size: 15px;
    font-weight: bold;
  }

il faut

.menu a {
  padding: 0 10px;
    display: block;
    height: 45px;
    text-align: left;
    line-height: 45px;
    color: #757575;
    font-size: 15px;
    font-weight: bold;
  }

sinon tu vas essayer par exemple de changer la couleur sur le premier bloc et tu ne vas pas comprendre pourquoi cela ne fonctionne pas vu que plus loin tu redéfinis la couleur.
Bonjour yiujia,

une fois de plus, un tout grand merci pour votre aide.

J'obtiens bien le résultat escompté.

En fait, j'ai des sélecteurs qui sont définis plusieurs fois car j'ai essayé de faire une solution responsive.

Je ne sais pas si vous êtes d'accord mais j'aimerais bien vous envoyer mon code pour avoir votre avis car je ne suis pas un expert en CSS et vous semblez être très doué.

Êtes-vous d'accord ?

Encore merci pour votre aide.

Je vous souhaite de passer une agréable soirée.

Thierry
Bonjour yiujia,

j'espère que vous allez bien ?

En tout cas, je tenais à vous remercier pour votre confiance ainsi que pour votre disponibilité.

Passez une agréable journée.

Thierry