Is it possible to resize a div with absolute position?
I want this pink modal to keep the same width of the input & resize with it.
This modal will be used in a dropdown component. So, should be resized as a whole with input.
By the way, is absolute position a correct choice for such a use case?
<!DOCTYPE html>
<html>
<head>
<title>My CSS Grid</title>
<style>
body {
color: #fff;
font-family: "Nunito Semibold";
text-align: center;
}
.page {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: minmax(100px, auto);
grid-gap: 10px;
max-width: 960px;
margin: 0 auto;
grid-template-areas:
"header header header"
"aside comp main";
}
.page > * {
background: #3bbced;
padding: 10px;
}
.header {
grid-area: header;
}
.comp {
grid-area: comp;
}
.input_cell {
display: grid;
}
.input {
flex: 1;
}
.modal_container {
margin-top: 20px;
flex: 1;
background-color: pink;
position: absolute;
}
</style>
</head>
<body>
<div class="page">
<div class="header">Header</div>
<div class="comp">
<div class="input_cell">
<input class="input" />
<div class="modal_container">Modal</div>
</div>
</div>
</div>
</body>
</html>
2
Answers
you didn’t have to use absolute position. just by giving
width: 100%
to both input and modal, problem is solved, no need to display grid.Set
.comp
,.input_cell
position relative. Styling.modal_container
width 100%