<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="parent">
<div class="child">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
</div>
</body>
</html>
style.css
.parent {
display: flex;
width:50%;
background-color: blue;
}
.child {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
aspect-ratio: 1;
background-color: green;
}
.item {
width: calc(100% / 7);
aspect-ratio: 1;
padding: 1%;
background-color: red;
box-sizing: border-box;
}
The child div width is not covering the whole width of parent.
According to me since there is no constraints of width the default behaviour of flex-item is to be the size of the content inside of it.
But since the content inside of it width is dependent on the parent itself, its causing a problem.
image output
Code Link: 42ruxwq27 - HTML - OneCompiler
I tried adding width as 100%, which resulted in the output that i desired, but most importantly
What i want is to know about this behaviour more when the child is dependent of the parents width and the parent is dependent on the childs width.