'Position absolute not inside parent
I have a problem with my CSS regarding div positions.
I have a parent div which is set to position:relative and a child div set to position:absolute
But for some reason the child div is displaying below and outside the borders of the parent div...
This is my CSS:
.big{
position:relative;
width:40%;
border:1px solid black;
display:inline-block;
}
.small{
position:absolute;
width:75px;
height:75px;
border:1px solid green;
}
The HTML:
<div class="big">
<p align="center">Test</p>
<div class="small"></div>
</div>
<div class="big">
<p align="center">Test</p>
<div class="small"></div>
</div>
I have provided a JSFiddle to show you it in action:
How do i fix it to make the child div be inside the parent div whilst using position:absolute for it?
Solution 1:[1]
As you have given a height of 75px to the child div and inside the parent div you have also given <p> which is a block element so the <p> tag is making its space and after that your child div is appearing....Make the div height of parent element larger than child and style the <p> tag to display: inline;
.big {
position: relative;
width: 40%;
height: 100px;
border: 1px solid black;
display: inline-block;
}
.small {
position: absolute;
width: 75px;
height: 75px;
border: 1px solid green;
}
p {
display: inline;
}
Hope this will get you to what you want.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | corn on the cob |
