Enrichir un span

Bonsoir,
Je cherche à enrichir un span du genre
<h1>mon_titre<span>mon_sous_titre</span></h1>
Le span hérite des "données" du parent. Comment faire pour l'enrichir si cela est possible ?
Merci pour votre aide,
E.

5 réponses

  • Votes
  • Date
  • Date décroissante
  1. Salut,

    enrichir je ne sais pas(ça doit coûter cher ;) ) mais on peut "styler" avec CSS comme n'importe quelle balise.

    Pour l'héritage ça dépends des propriétés mais on peut toujours indiquer une valeur si on veux changer.

    <!--Un style externe ou dans le head:-->
    .avecstyle{
    font-weight:bold;
    font-size:1.2em;
    }
    <!--Dans la page-->
    <h1>mon_titre<span class=avecstyle>mon_sous_titre</span></h1> 
    1. Modérateur
      Bonjour,

      Tout est expliqué ici : https://www.alsacreations.com/tuto/lire/545-Comprendre-l-heritage-et-la-parente-des-styles-CSS.html

      Exemple :
      
      <!DOCTYPE html>
      <html>
       <head>
         <meta charset="utf-8" />        
         <title>TEST</title>   
      
         <style>
         
         /* span normal */
         span{
          color:black;
         }
         
         /*h1*/
         h1{
          font-size: 250%;
         }
         
         /* si span dans un h1 */
         h1 span{
          color : red;
         }
      
        </style>
        </head>
        <body>
          
          <span> ceci est un span "normal"</span>
          <h1>Mon titre h1 <span> ceci est un span "hérité de h1"</span></h1>
      
        </body> 
      </html>
      

      1. Merci à vous, mais dans mon cas :
        ".h1 span: " ne joue que sur la couleur (pas sur l'interlettrage etc...).
        Je vais tenter de styliser (er non enrichir ;) tout ça et revient vers vous !
        Merci et bonne soirée,
        E.
        1. Modérateur
          Sachant que tu ne dois pas mettre de point devant h1 ...
      2. Bonsoir à tous,
        Dans mon cas, cela ne fonctionne pas :( Problème de code ?
        Mes CSS ressemble à ceci :
        .header h1 {
        	margin-right: 0;
        	margin-left: 0;
        	margin-bottom: 0;
        	margin-top: 50px;
        	letter-spacing: -1px;
        	line-height: 0.8em;
        	font-weight: normal;
        	font-variant: normal;
        	font-style: normal;
        	font-size: 5em;
        	font-family: luckiestguy;
        	color: #FF9900;
        	text-align: center;
        	word-spacing: -0.1em;
        }
        
        .sous_titre {
        	font-size: 0.6em;
        	word-spacing: normal;
        	line-height: 0em;
        }

        et mon body à ceci :
         <h1>dessins originaux. com<br>
        <span class="sous_titre">original artworks</span></h1>

        le line-height est hérité de header h1. Le résultat est monstrueux, je ne trouve pas le moyen d'en changer.
        Merci pour votre aide,
        E.
      3. Bonjour jordane45 et merci pour ton lien; mais rien à faire :/ J'arrive à changer le font-size, la couleur mais le line-height... :(
        Mes CSS :
        header {
        margin-top: 10px;
        margin-left: 0px;
        margin-right: 0px;
        }
        header h1 {
        margin-bottom: 0;
        margin-top: 50px;
        letter-spacing: -1px;
        line-height: 0.8em;
        font-weight: normal;
        font-variant: normal;
        font-style: normal;
        font-size: 5em;
        font-family: luckiestguy;
        color: #FFFFFF;
        text-align: center;
        word-spacing: -0.1em;
        }
        header h1 span {
        font-size: 0.6em;
        line-height: 0.1 !important;
        color: #D3C1A5;
        }

        Une idée ?
        Merci et bonne fin de journée,
        E.