The reason for this issue stems from the parent <div class="col">
having a style of
padding-left: 15px; padding-right: 15px
, while the child
<div class="image-text p-4">
has a
position: absolute
. Since absolute positioning disregards the padding of the parent (see: Absolute positioning ignoring padding of parent), the width of your child becomes
expected width
+
padding-left
+
padding-right
.
To address this, you have a couple of options:
- Remove the padding from the parent if it is not necessary with
<div class="col" style="padding:0">
. For example: https://codepen.io/prasadkothavale/pen/jxmbww
If you wish to keep the padding, then you can add a wrapper <div class="wrapper">
around the absolute child
<div class="image-text p-4">
and apply the following CSS:
.wrapper {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
padding-left: 15px;
padding-right: 15px;
}
Furthermore, remove
position: absolute; bottom: 0; width: 100%
from the child element. Refer to this example:
https://codepen.io/prasadkothavale/pen/xjdwjB