The justifyContent
property gets and sets how to
align the flexible container's items when the
items do not use all available space horizontally.
justifyContent |
Yes | Yes | Yes | Yes | Yes |
Return the justifyContent property:
var v = object.style.justifyContent
Set the justifyContent property:
object.style.justifyContent='flex-start|flex-end|center|space-between|space-around|initial|inherit'
Default Value: | flex-start |
---|---|
Return Value: | A string representing the justify-content property |
CSS Version | CSS3 |
The following code shows how to add some space between the items of the flexible <div> element.
<!DOCTYPE html>
<html>
<head>
<style>
#main {<!--from ww w . j av 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:red;">A</div>
<div style="background-color:blue;">B</div>
<div style="background-color:yellow;">C</div>
<div style="background-color:pink;">D</div>
</div>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("main").style.justifyContent = "space-between";
}
</script>
</body>
</html>
The code above is rendered as follows: