0

I have two questions:

  1. Why does padding on inline elements work I have read that padding on inline element should not work.
  2. Why does the padding push the span above the div container:

http://jsfiddle.net/L76e208g/1/

body > div {
    width: 150px;
    height: 150px;
    background: black;
    margin-top: 40px;
    display: inline-block;
    vertical-align: bottom;
}

div > div,
div > span{
    border-radius: 5px;
    padding: 10%;
    background: red;
}
<div>
  <div>
  </div>
</div>
<div>
  <span>
  </span>
</div>
ivaylo
  • 811
  • 2
  • 9
  • 25

1 Answers1

1

It's not that padding doesn't apply at all to inline elements, rather that their top and bottom values won't be taken into account as far as "pushing away" content in preceding/successive lines. More on that here.

body>div {
  width: 150px;
  height: 150px;
  background: black;
  margin-top: 40px;
  display: inline-block;
  vertical-align: bottom;
  color: white;
}

div>div,
div>span {
  border-radius: 5px;
  padding: 10%;
  background: red;
}
<div>Lorem ipsum dolor sit amet consectetur
  <div>Lorem ipsum dolor</div> consectetur adipisicing elit.</div>
<div>Lorem ipsum dolor sit amet consectetur <span>Lorem ipsum dolor</span> consectetur adipisicing elit.</div>
Ito Pizarro
  • 1,607
  • 1
  • 11
  • 21