Was looking at the vertical-align
property of CSS
. I have used it quite a bit and normally you can use it like this:
div {
background-color: green;
overflow: hidden;
height: 100px;
}
#text {
background-color: powderblue;
padding: 5px;
vertical-align: 30px;
}
<div>
Texttext <span id="text">Texttext</span>Texttext
</div>
However, what I don't understand is that if the vertical-align
is changed this can influence the position of the other inline elements (other text in this case)
For example if we change the vertical-align
from 30px to -30px:
div {
background-color: green;
overflow: hidden;
height: 100px;
}
#text {
background-color: powderblue;
padding: 5px;
vertical-align: -30px;
}
<div>
Texttext <span id="text">Texttext</span>Texttext
</div>
The results is that text outside the span (with no vertical-align
property) is completely changed from position.
Questions
- Why does vertical align also affects other elements besides the element where the property is put on?
- Is this anyhow related to line-height? Can line-height change the behaviour of the
vertical-align
property?