Javascript examples for CSS Style Property:justifyContent
The justifyContent property aligns the flexible items when the items do not use all available space horizontally.
Value | Description |
---|---|
flex-start | Default value. Items are positioned at the beginning of the container |
flex-end | positioned at the end of the container |
center | positioned at the center of the container |
space-between | positioned with space between the lines |
space-around | positioned with space before, between, and after the lines |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
Item | Value |
---|---|
Default Value: | flex-start |
Return Value: | A String, representing the justify-content property of an element |
CSS Version | CSS3 |
Make some space between the items of the flexible <div> element:
<!DOCTYPE html> <html> <head> <style> #main {//w w w .jav a2 s . c om width: 400px; height: 150px; border: 1px solid #000000; display: flex; justify-content: space-around; } #main div { width: 70px; height: 70px; } </style> </head> <body> <div id="main"> <div style="background-color:coral;"></div> <div style="background-color:red;"></div> <div style="background-color:khaki;"></div> <div style="background-color:pink;"></div> </div> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("main").style.justifyContent = "space-between"; } </script> </body> </html>