Absolute positioning ignoring padding of parent

How do you make an absolute positioned element honor the padding of its parent? I want an inner div to stretch across the width of its parent and to be positioned at the bottom of that parent, basically a footer. But the child has to honor the padding of the parent and it’s not doing that. The child is pressed right up against the edge of the parent.

So I want this:

enter image description here

but I’m getting this:

enter image description here

<html>
  <body>
    <div style="background-color: blue; padding: 10px; position: relative; height: 100px;">
      <div style="background-color: gray; position: absolute; left: 0px; right: 0px; bottom: 0px;">css sux</div>
    </div>
  </body>
</html>

I can make it happen with a margin around the inner div, but I’d prefer not to have to add that.

9 Answers
9

Leave a Comment