Justin Erswell
Justin Erswell

Reputation: 708

Firefox ::after pseudo element not working

I have a CSS class which outputs a line after a title

enter image description here

This works in Safari and Chrome but in Firefox the line is not appearing.

My Code:

.sidebar h2 {
    color: #f7f7f7;
    width: 100%;
    font-size: 24px;
    position: relative;
}

.sidebar h2 span {
    background-color: #40d1b0;
    padding-right: 2px;
}
.sidebar h2::after {
    content:"";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0.22em;
    border-top: 1px solid rgba(0,0,0,0.10);
    z-index: -1;
}

<h2><span>Show</span></h2>

The container div has a class of Sidebar

EDIT

JSFiddle as requested

http://jsfiddle.net/jerswell/Lxsmt96k/

Upvotes: 5

Views: 7222

Answers (2)

Shyam
Shyam

Reputation: 792

If we change z-index of .sidebar in minus value, later it can have a problem for layout. Other elements can overlap this element. We should use :

.sidebar h2{position:relative;}
.sidebar h2 span{position:relative;z-index:2;}
.sidebar h2:after{z-index:1;}

Upvotes: 0

meskobalazs
meskobalazs

Reputation: 16041

The problem is the z-index, put a lower z-index to the sidebar class, so it won't be hidden anymore.

Here is a new fiddle, I have just simply put z-index: -2; to the .sidebar selector.

PS (nitpicking): In CSS3 after is not a pseudo-class but a pseudo-element, and there is a new notation for it: ::after (however the old notation still works)

Upvotes: 4

Related Questions