У меня есть корневой div с максимальной шириной, а затем контейнер и несколько дочерних элементов в абсолютном значении.
.root {
background-color: tomato;
max-width: 400px;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.container {
position: relative;
}
.item {
background-color: steelblue;
width: 100px;
height: 100px;
position: absolute;
}<div class = "root">
<div class = "container ">
<div class = "item" style = "top: 0px; left: 0px"></div>
<div class = "item" style = "top: 0px; left: 110px"></div>
<div class = "item" style = "top: 0px; left: 220px"></div>
<div class = "item" style = "top: 110px; left: 0px"></div>
</div>
</div>Почему не виден томатный фон? Почему этот div имеет высоту = 0?
Чего я хочу добиться, так это корневого div с максимальной шириной, а затем некоторых дочерних элементов в абсолютной позиции, которые не переполняют родительский div






Замени height на .root100% на 100vh
.root {
background-color: tomato;
max-width: 400px;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.container {
position: relative;
}
.item {
background-color: steelblue;
width: 100px;
height: 100px;
position: absolute;
}<div class = "root">
<div class = "container ">
<div class = "item" style = "top: 0px; left: 0px"></div>
<div class = "item" style = "top: 0px; left: 110px"></div>
<div class = "item" style = "top: 0px; left: 220px"></div>
<div class = "item" style = "top: 110px; left: 0px"></div>
</div>
</div>У вашего корня нет высоты. Когда вы устанавливаете абсолютную позицию своих предметов, вы удален элемент из обычного потока документов, и для элемента не создается место в макете страницы
.root {
background-color: tomato;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.container {
}
.item {
background-color: steelblue;
width: 100px;
height: 100px;
position: absolute;
}<div class = "root">
<div class = "container ">
<div class = "item" style = "top: 0px; left: 0px"></div>
<div class = "item" style = "top: 0px; left: 110px"></div>
<div class = "item" style = "top: 0px; left: 220px"></div>
<div class = "item" style = "top: 110px; left: 0px"></div>
</div>
</div>