Shah-Center-Div

This will teach the user how to make child Div to center of parent Div element.

by Md Shah

HTML

<div align="center" class="noresult">
    <div class="mainback noresultimg"></div>
    <span class="noresulttxt">(blablablablablablablablablablablabl abl blablablablc)</span>

</div>

CSS

div.noresult {
    width:100%;
    height:150px;
    position:relative;
    border:1px solid red;
}
div.noresult div.noresultimg {
    background-position: -1130px 0px;
    height: 150px;
    width: 126px;
    margin: 0px auto -1px auto;
    background-color: red;
}
div.noresult span.noresulttxt {
    font-size:14px;
    position:absolute;
    top:90px;
    color:#663333;
    white-space:nowrap;
}

JavaScript

$(document).ready(function (e) {

    var mainDivWidth = $('.noresult').css('width').replace('px', '');
    var childSpanWidth = $('.noresulttxt').css('width').replace('px', '');
    var leftSpan = (mainDivWidth - childSpanWidth) / 2 + 'px';
    $('.noresulttxt').css('left', leftSpan);
});