Vikas Ghodke
Vikas Ghodke

Reputation: 6665

Absolute Centering Not Working in IE

I have a div which is centered in parent div, it working on all browser but not in ie, can you help me out with this.

JSFIDDLE

enter image description here

span.qbg3 {
    display: block;
    text-align: center;
    background: url(http://powerblanket.com/may2014/wp-content/uploads/2014/05/qbg3.png) no-repeat center center;
    background-size:cover;
    padding: 50px 20px;
    color: #fff;
    font-weight: 400;
    font-size: 30px;
    position: relative;
    margin-top: -20px;
    min-height: 350px;
}
span.inqbg3 {
    max-height: 100px;
    display: block;
    text-align: center;
    color: #fff;
    font-weight: 400;
    font-size: 40px;
    position: absolute;
    margin: auto;
    top: 0px;
    right: 0;
    left: 0;
    bottom: 0px;
    background: rgba(0, 0, 0, 0.5);
    max-width: 700px;
    padding: 35px 0;
}
span.inqbg3 a {
    color: #fff;
}

Upvotes: 0

Views: 100

Answers (3)

4dgaurav
4dgaurav

Reputation: 11496

Demo

You need to set width of the span.inqbg3 as

width: 100% /* Set your own height: percents, ems, whatever! */

CSS

span.inqbg3 {
    height: 100%; /* Set your own height: percents, ems, whatever! */
    max-height: 100px;
    display: block;
    text-align: center;
    color: #fff;
    font-weight: 400;
    font-size: 40px;
    position: absolute;
    margin: auto;
    top: 0px;
    right: 0;
    left: 0;
    bottom: 0px;
    background: rgba(0, 0, 0, 0.5);
    width: 100%; /* Set your own width: percents, ems, whatever! */
    max-width: 700px;
    padding: 35px 0;
}

enter image description here

Upvotes: 1

Prashant Tapase
Prashant Tapase

Reputation: 2147

Remove position: absolute; from span.inqbg3 .

Upvotes: 0

Tushar
Tushar

Reputation: 4418

You need to change your css

Need to remove right: 0 and bottom: 0

and change left: 0 and top: 0 to left: 50% and top: 50% and half minus height and width margin to bring it in center.

CSS

span.inqbg3 {
    max-height: 100px;
    display: block;
    text-align: center;
    color: #fff;
    font-weight: 400;
    font-size: 40px;
position: absolute;
margin:  -85px 0 0 -267px;
top: 50%;
/* right: 0; */
left: 50%;
/* bottom: 0px; */
    background: rgba(0,0,0,0.5);
    max-width: 700px;
    padding: 35px;
}

Here is the demo

Upvotes: 1

Related Questions