I have a parent div that has the max-width: 100%
(full screen width) and I want to make the child div to have the same width, but I don't know why it's not working. I tried child div width: 100%
and width: inherit
but still it has a margin. Is there a solution? The parent div contains a carousel above this child div.
What I want to remove is this margin: the margin
For the child div I already used (you can see in the html below) bootstrap classes for margins, ms-0 and me-0;
The parent div looks good, the margins are fine, has no margin from the browser.
I tried all the solutions offered here Cross browser method to fit a child div to its parent's width but it's not working.
.main {
position : relative;
height : auto;
left : 0px;
right : 0px;
background-color : #eceaed;
max-width : 100%;
}
.middle-box {
position : relative;
height : 250px;
max-width : 100%;
border : 1px solid black;
background-color : rgba(96, 75, 254, 0.8);
}
.middle-box::before {
content : "";
background-image : url("../images/mountains2.jpg");
background-size : cover;
position : absolute;
top : 0px;
right : 0px;
bottom : 0px;
left : 0px;
opacity : 0.3;
}
<div class="container main">
<!--here is a div with a carousel-->
<div class="container middle-box ms-0 me-0">
</div>
</div>
Solution:
.main {
padding : 0;
}
.middle-box {
max-width : 100%;
}
.middle-box::before {
max-width : 100%;
}