Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Element ignores padding of container element

Tags:

html

css

I have the following HTML/CSS code:

<div id="container" style="padding:5px; width:600px;">  
    <div id="panel">
        <a style="padding:5px; color:#ffffff; background-color:#000000;">Page 1</a>

        <!-- Other anchor elements -->
    </div>

    <!-- Other panels -->
</div>

I struggle to understand why the #panel element sits comfortably within the #container; obeying the padding rules of it, whereas padding of the anchor element within the #panel overlaps the #container. Would anyone mind explaining why this is the case, and in doing so, perhaps suggest a fix?

like image 897
TheBoss Avatar asked Sep 05 '12 02:09

TheBoss


1 Answers

I think because its an inline element this occurs, if you change its display to inline-block the padding no longer overlaps. DEMO

like image 99
Musa Avatar answered Sep 16 '22 18:09

Musa