Problems with :before and :after in Internet Explorer 10

Eric Bergman picture Eric Bergman · Oct 31, 2013 · Viewed 12.6k times · Source

This basically adds two lines before and after the h1 element, like this: The line is just a background color with a height of 1px.

------------------------ Some Text ------------------------

I tested this in Chrome and Firefox and everything works properly but when I test it in Internet Explorer 10 the LEFT line is not displayed.

Checkout the JSFiddle

Answer

Mr. Zoidberg picture Mr. Zoidberg · Oct 31, 2013

Here is your solution:

.ItemHeader div h1 {
    position:relative;
    overflow:hidden;
    z-index: 1;
    text-align: center;
    font-weight:bold;
    font-size: 0.8em;
}
.ItemHeader div h1:before, .ItemHeader div h1:after {
    top: 50%;
    overflow:hidden;
    height: 1px;
    content:"\a0";
    background-color:#a2a2a2;
    position: absolute;
    width:50%;
}
.ItemHeader div h1:before {
    left:-5%;
    text-align: right;
}
.ItemHeader div h1:after {
    left:55%;
}
<div class="item-block">
    <div class="ItemHeader">
        <div>
            <h1>Application</h1>
        </div>
    </div>
</div>

Remove the margin-left properties in your code and use left instead.

It's working fine in both Chrome and IE10.

JSFiddle: http://jsfiddle.net/4KX3u/7/