Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:before && :after pseudo elements not showing Firefox

Tags:

html

css

firefox

Firefox is not displaying :after and :before but they do show in Chrome.

Firefox & Chrome: enter image description here

Viewing the source directly in Firefox shows the CSS is there: enter image description here

This is happening on multiple elements on the page using :after.

I have tried using both before and after. I have also tried both :: and : variations.

If I use the same CSS in codepen it works: http://codepen.io/anon/pen/XXOZWL

<input type="checkbox" class="mobile_auth" />

.mobile_auth {
    visibility: hidden;
}

.mobile_auth:after {
    background-image: url('https://lh4.googleusercontent.com/-gD_ItALdha8/AAAAAAAAAAI/AAAAAAAAAB4/eEbUyChzCJc/photo.jpg?sz=110');
    content: '';
    height: 33px;
    width: 33px;
    display: block;
    cursor: pointer;
    visibility: visible;
    margin: auto;
    position: relative;
    top: -3px;
    left: 3px;
}

.mobile_auth::after {
    background-image: url('https://lh4.googleusercontent.com/-gD_ItALdha8/AAAAAAAAAAI/AAAAAAAAAB4/eEbUyChzCJc/photo.jpg?sz=110');
    content: '';
    height: 33px;
    width: 33px;
    display: block;
    cursor: pointer;
    visibility: visible;
    margin: auto;
    position: relative;
    top: -3px;
    left: 3px;
}

.mobile_auth:checked:after {
    background-position: right;
}

You can see the page live at: ***.com login with User: demo Pass: demo and click 'config'. Lots of buttons are missing in the latest Firefox.

It's strange because it doesn't show at all. It's not like the element is there and I can't see it. It isn't even showing that it exists in console.

like image 545
Jack Avatar asked Feb 13 '16 09:02

Jack


2 Answers

You cannot use ::after and ::before on elements that cannot have content, such as <input /> or <img />.

::after and ::before work like this:

<element>
  ::before
  ***content***
  ::after
</element>
<next-element>***content***</next-element>

They get inserted before and after the content of a DOM node. Since <input /> cannot have content, there's nowhere to put it.

Now let's check with a checkbox:

<input type="checkbox" />
<next-element>***content***</next-element>

Here, there cannot be ***content*** to surround with pseudo elements.

like image 71
connexo Avatar answered Sep 24 '22 00:09

connexo


The expected behavior can be enabled for Firefox browsers by using the following on the input[type=checkbox]:

input[type=checkbox] {
  -moz-appearance:initial // Hack for Firefox Browsers
}

This option allows you to use :before pseudo-elements on the input-element, just like it works out of the box for Safari and Chrome and Opera Browsers:

input[type=checkbox]::before { 
    ...
}

The moz-appearance is currently experimental technology. More information along with an overview of Browser compatibility can be obtained here: MDN web docs - appearance.

like image 23
Kevin Katzke Avatar answered Sep 22 '22 00:09

Kevin Katzke