As the OP stated:
I need the span centered with respect to the whole site.
One option could be to position the <span>
element absolute
ly and align the text to the center horizontally and vertically as follows:
Method #1:
Using top
/left
and transform
properties:
.wrapper {
position: relative;
height: 100px; background-color:black; color:white;
}
.wrapper > span.hejsa {
position: absolute;
top: 50%; left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<div class="wrapper">
<img style="height:100px;" src="http://www.kiplinger.com/quiz/business/T049-S001-test-your-start-up-know-how/images/all-small-businesses-have-to-be-incorporated1.jpg" />
<span class="hejsa">
Lorem ipsum dolor sit amet...
</span>
</div>
It's worth noting that CSS transform is not supported in IE8 and olders (which is not the OP's concern as s/he mentioned in comments)
Method #2:
Expanding the absolutely positioned <span>
element by top
/right
/bottom
/left
properties:
.wrapper {
position: relative;
height: 100px; background-color:black; color:white;
}
/* .wrapper > img { position: relative; z-index: 1; } */ /* optional */
.wrapper > span.hejsa {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
line-height: 100px;
text-align: center;
}
<div class="wrapper">
<img style="height:100px;" src="http://www.kiplinger.com/quiz/business/T049-S001-test-your-start-up-know-how/images/all-small-businesses-have-to-be-incorporated1.jpg" />
<span class="hejsa">
Lorem ipsum dolor sit amet...
</span>
</div>
This method has a wider browser support, however one drawback of it is the text should not be multiline.