I'm trying to understand why the following code does not creates a scrollable flexbox.
var firstData = ["One", "Two", "Three", "Four"]
FillDiv();
FillDiv();
$("button").on('click', function() {
FillDiv();
});
function FillDiv() {
var newData = GetData();
for (i = 0; i < newData.length; i++) {
$(".wrapper").append('<div>Test</div>');
}
}
function GetData() {
return firstData;
}
.wrapper {
display: flex;
overflow-x: auto;
}
.wrapper div {
display: block;
width: 200px;
height: 200px;
background-color: black;
color: white;
text-align: center;
margin-left: 1%;
}
button {
margin-top: 20px;
margin-left: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrapper">
</div>
<button>
NEXT
</button>
However, the following example does:
.container {
display: flex;
overflow-x: auto;
}
<div class="container">
<img src="https://as1.ftcdn.net/jpg/02/12/43/28/500_F_212432820_Zf6CaVMwOXFIylDOEDqNqzURaYa7CHHc.jpg" alt="">
<img src="https://as1.ftcdn.net/jpg/02/12/43/28/500_F_212432820_Zf6CaVMwOXFIylDOEDqNqzURaYa7CHHc.jpg" alt="">
<img src="https://as1.ftcdn.net/jpg/02/12/43/28/500_F_212432820_Zf6CaVMwOXFIylDOEDqNqzURaYa7CHHc.jpg" alt="">
<img src="https://as1.ftcdn.net/jpg/02/12/43/28/500_F_212432820_Zf6CaVMwOXFIylDOEDqNqzURaYa7CHHc.jpg" alt="">
<img src="https://as1.ftcdn.net/jpg/02/12/43/28/500_F_212432820_Zf6CaVMwOXFIylDOEDqNqzURaYa7CHHc.jpg" alt="">
<img src="https://as1.ftcdn.net/jpg/02/12/43/28/500_F_212432820_Zf6CaVMwOXFIylDOEDqNqzURaYa7CHHc.jpg" alt="">
</div>
Why does the scroll breaks when I add width and height in first example?