/

HTML / CSS / JavaScript Tutorial

CSS Property: flex-wrap

[this page | pdf | back links]

The CSS (CSS3) flex-wrap property indicates whether flexible items should wrap. If an element is not a flexible element then this property has no effect.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

nowrap

(default value). Will not wrap

wrap

Will wrap if necessary

wrap-reverse

Will wrap if necessary, but in reverse order

 

Default Value:

nowrap

JavaScript syntax:

e.g. object.style.flexWrap="wrap-reverse"

Inherited:

No

Animatable:

No

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
.x1 {display: flex; width: 40px; flex-wrap: wrap-reverse;}
</style>
</head>
<body>
1. Element with default property<br>
<div style="display: flex; width: 40px">
<div>text 1</div><div>text 2</div><div>text 3</div>
</div>
<br>
2. Element set using in-file HTML style<br>
<div class="x1">
<div>text 1</div><div>text 2</div><div>text 3</div>
</div>
<br>
3. Element set using JavaScript<br>
<div id="x2">
<div>text 1</div><div>text 2</div><div>text 3</div>
</div>
<br>

<script>
document.getElementById("x2").style.width = "40px";
document.getElementById("x2").style.display = "flex";
document.getElementById("x2").style.flexWrap = "wrap-reverse";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyFlexWrap() {
  var x = document.createElement("DIV"); x.style.flexWrap = "wrap-reverse"; return (window.getComputedStyle(x, null).flexWrap == "wrap-reverse");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile