Comparaison binaire des n premiers caractères
La propriété flex définit la longueur flexible sur les éléments flexibles. Si l'élément n'est pas un élément flexible, la propriété flex n'a aucun effet.
flex: flex-grow flex-shrink flex-basis|auto|initial|inherit;
Valeurs par défaut | 0 1 auto |
---|---|
Inherited: | non |
Animable : | oui En savoir plus sur l'animable |
Version: | CSS3 |
Syntaxe JavaScript: | object.style.flexShrink="1" |
Exemple Copier le code
<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <title> Propriété CSS flex </title> <style> body { background-color:#E7E9EB; } #myDIV { width: 100%; height:100%; background-color:#FFFFFF; margin:auto; } #mymain {height:100%; width: 100%; display: flex; } #mymain div { padding:1em;height:100%; } #divBleu{flex: 0 1 60%} #divRouge { flex: 0 1 20%; } #divJaune{flex: 0 1 20%;} </style> </head> <body> <h1>La propriété css flex</h1> <div id="myDIV"> <h2>Définissez la propriété flex des div Rouge, Blue et Jaune :</h2> <div id="mymain"> <div id="divRouge" style="background-color:coral;"> <h2>div rouge</h2> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Diam maecenas sed enim ut sem viverra aliquet eget sit.</div> <div id="divBleu" style="background-color:lightblue;"> <h2>div bleu</h2> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ac turpis egestas sed tempus urna et. Suspendisse potenti nullam ac tortor vitae purus faucibus ornare. Vitae auctor eu augue ut lectus arcu. Ac orci phasellus egestas tellus rutrum tellus. Mattis aliquam faucibus purus in massa. </div> <div id="divJaune" style="background-color:khaki;"> <h2>div jaune</h2> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Diam maecenas sed enim ut sem viverra aliquet eget sit. </div> </div> </div> </body> </html>
flex-grow: nombre| initial| inherit;
Valeurs par défaut | 0 |
---|---|
Inherited: | non |
Animable : | oui En savoir plus sur l'animable |
Version: | CSS3 |
Syntaxe JavaScript: | object.style.flexGrow="5" |
Exemple Copier le code
<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <title> Propriété CSS flex-grow </title> <style> body { background-color:#E7E9EB; } #myDIV { width: 100%; background-color:#FFFFFF; margin:auto; } #mymain { width: 100%; display: flex; } #mymain div { padding:1em; } #divRouge {flex-grow: 1 ;} #divBleu{flex-grow: 3 ;} #divJaune{flex-grow: 1 ;} </style> </head> <body> <h1>La propriété css flex-grow</h1> <div id="myDIV"> <h2>Définissez la propriété flex-grow des div: Rouge, Blue et Jaune :</h2> <div id="mymain"> <div id="divRouge" style="background-color:coral;"> <h2>div rouge</h2> </div> <div id="divBleu" style="background-color:lightblue;"> <h2>div bleu</h2> </div> <div id="divJaune" style="background-color:khaki;"> <h2>div jaune</h2> </div> </div> </div> </body> </html>
flex-shrink: nombre|initial|inherit;
Valeurs par défaut | 1 |
---|---|
Inherited: | non |
Animable : | oui En savoir plus sur l'animable |
Version: | CSS3 |
Syntaxe JavaScript: | object.style.flexShrink="5" |
Exemple Copier le code
<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <title> Propriété CSS flex-shrink </title> <style> #main { width: 550px; height: 100px; border: 1px solid #c3c3c3; display: flex; } #main div { flex-shrink: 1; flex-shrink: 1; flex-basis: 100px; font-size:10px; padding: 5px; } #main div:nth-of-type(2) { flex-shrink: 5; } </style> </head> <body> <h1>La propriété CSS flex-shrink </h1> <div id="main"> <div style="background-color:coral;"><h2>flex-shrink: 1</h2></div> <div style="background-color:lightblue;"><h2>flex-shrink: 5</h2></div> <div style="background-color:khaki;"><h2>flex-shrink: 1</h2></div> <div style="background-color:pink;"><h2>flex-shrink: 1</h2></div> <div style="background-color:lightgreen;"><h2>flex-shrink: 1</h2> </div><div style="background-color:lightgrey;"><h2>flex-shrink: 1</h2></div> </div> </body> </html>
flex-basis: nomber|auto|initial|inherit;
Valeurs par défaut | auto |
---|---|
Inherited: | non |
Animable : | ouiEn savoir plus sur l'animable |
Version: | CSS3 |
Syntaxe JavaScript: | object.style.flexBasis="200px" |
Explorateur | |||||
---|---|---|---|---|---|
Verssion | 29 21 -webkit- | 11 10-ms- | 28 18 -moz- | 9 6.1 -webkit- | 17 |
Exemple Copier le code
<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <title> Modifier la propriété CSS flex avec JavaScript </title> <style> #main { width: 250px; height: 100px; border: 1px solid #c3c3c3; display: flex; } #main div { flex: 0 0 50px; } </style> </head> <body> <h1>Changer la propriété CSS flex avec JavaScript</h1> <div id="main"> <div style="background-color:coral;">Red DIV</div> <div style="background-color:lightblue;" id="divBleu">Blue DIV</div> </div> <p>Cliquez sur le bouton "CHANGER" pour définir la valeur de la propriété flex à "200px" pour l'élément div bleu.</p> <button onclick="FonctionChanger()"> CHANGER </button> <script> function FonctionChanger() { document.getElementById("divBleu").style.flex = "0 0 200px"; } </script> </body> </html>