Catatan: contoh ini menggunakan ukuran font yang berbeda untuk menunjukkan bahwa item disejajarkan dengan garis dasar teks: Show Properti align-contentProperti <!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; flex-direction: row-reverse; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; width: 100px; margin: 10px; text-align: center; line-height: 75px; font-size: 30px; } </style> </head> <body> <h1>The flex-direction Property</h1> <p>The "flex-direction: row-reverse;" menumpuk item flex secara horizontal (tapi dari kanan ke kiri):</p> <div class="flex-container"> <div>1</div> <div>2</div> <div>3</div> </div> </body> </html>0 digunakan untuk meratakan garis fleksibel. Contoh <!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; flex-direction: column; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; width: 100px; margin: 10px; text-align: center; line-height: 75px; font-size: 30px; } </style> </head> <body> <h1>The flex-direction Property</h1> <p>The "flex-direction: column;" menumpuk item flex secara vertikal (dari atas ke bawah):</p> <div class="flex-container"> <div>1</div> <div>2</div> <div>3</div> </div> </body> </html>9 Contoh <!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; flex-direction: column-reverse; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; width: 100px; margin: 10px; text-align: center; line-height: 75px; font-size: 30px; } </style> </head> <body> <h1>The flex-direction Property</h1> <p>The "flex-direction: column-reverse;" menumpuk item flex secara vertikal (tapi dari bawah ke atas):</p> <div class="flex-container"> <div>1</div> <div>2</div> <div>3</div> </div> </body> </html>0 Contoh <!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; flex-direction: column-reverse; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; width: 100px; margin: 10px; text-align: center; line-height: 75px; font-size: 30px; } </style> </head> <body> <h1>The flex-direction Property</h1> <p>The "flex-direction: column-reverse;" menumpuk item flex secara vertikal (tapi dari bawah ke atas):</p> <div class="flex-container"> <div>1</div> <div>2</div> <div>3</div> </div> </body> </html>1 Contoh <!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; flex-direction: column-reverse; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; width: 100px; margin: 10px; text-align: center; line-height: 75px; font-size: 30px; } </style> </head> <body> <h1>The flex-direction Property</h1> <p>The "flex-direction: column-reverse;" menumpuk item flex secara vertikal (tapi dari bawah ke atas):</p> <div class="flex-container"> <div>1</div> <div>2</div> <div>3</div> </div> </body> </html>2 Contoh <!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; flex-direction: column-reverse; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; width: 100px; margin: 10px; text-align: center; line-height: 75px; font-size: 30px; } </style> </head> <body> <h1>The flex-direction Property</h1> <p>The "flex-direction: column-reverse;" menumpuk item flex secara vertikal (tapi dari bawah ke atas):</p> <div class="flex-container"> <div>1</div> <div>2</div> <div>3</div> </div> </body> </html>3 Contoh <!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; flex-direction: column-reverse; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; width: 100px; margin: 10px; text-align: center; line-height: 75px; font-size: 30px; } </style> </head> <body> <h1>The flex-direction Property</h1> <p>The "flex-direction: column-reverse;" menumpuk item flex secara vertikal (tapi dari bawah ke atas):</p> <div class="flex-container"> <div>1</div> <div>2</div> <div>3</div> </div> </body> </html>4 Perfect CenteringDalam contoh berikut, kita akan menyelesaikan masalah gaya yang sangat umum: perfect centering. Contoh : <!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; flex-direction: column-reverse; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; width: 100px; margin: 10px; text-align: center; line-height: 75px; font-size: 30px; } </style> </head> <body> <h1>The flex-direction Property</h1> <p>The "flex-direction: column-reverse;" menumpuk item flex secara vertikal (tapi dari bawah ke atas):</p> <div class="flex-container"> <div>1</div> <div>2</div> <div>3</div> </div> </body> </html>5 SOLUSI: Setel properti <!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; flex-direction: row; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; width: 100px; margin: 10px; text-align: center; line-height: 75px; font-size: 30px; } </style> </head> <body> <h1>The flex-direction Property</h1> <p>The "flex-direction: row;" menumpuk item flex secara horizontal (dari kiri ke kanan):</p> <div class="flex-container"> <div>1</div> <div>2</div> <div>3</div> </div> </body> </html>8 dan <!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; flex-direction: row; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; width: 100px; margin: 10px; text-align: center; line-height: 75px; font-size: 30px; } </style> </head> <body> <h1>The flex-direction Property</h1> <p>The "flex-direction: row;" menumpuk item flex secara horizontal (dari kiri ke kanan):</p> <div class="flex-container"> <div>1</div> <div>2</div> <div>3</div> </div> </body> </html>9 ke tengah dan item flex akan berada di tengah dengan sempurna: Display Flex CSS untuk apa?6. Flex. Flex (flexibel) adalah salah satu super power display dari CSS3. Memungkinkan untuk pengaturan layout, posisi dan tampilan dari suatu konten yang ukurannya belum diketahui atau bernilai dinamis.
Flex direction untuk apa?Nama properti ini adalah flex-direction, digunakan untuk mengatur arah Main Axis. Nilai default dari flex-direction adalah row, yang artinya Main Axis kita berada di sumbu horizontal, bergerak dari kiri ke kanan.
Justify Content CSS untuk apa?Justify-content dan align-items adalah dua properti CSS yang membantu kita mendistribusikan item-item di dalam container. Mereka mengontrol bagaimana item diposisikan secara horizontal (main axis) maupun vertikal (cross axis).
|