Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS ::after content doesn't seem to work as expected. What am I doing wrong?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #266044
    vsajip
    Participant

    On Firefox, the labels of checkboxes and radio buttons are very close to the actual boxes themselves, when marked up like this:

    Markup

    To illustrate, below is an image showing Firefox on the left vs. Chrome on the right.

    Example

    I can overcome this by placing a   immediately after the input tag, which I have done for the third option in the following:

    Example

    However, I would like to achieve the same effect using the CSS ::after feature. I tried the following CSS:

    .firefox .checkbox input[type=checkbox]::after, .firefox .radio input[type=radio]::after {
      content: " ";
      white-space: pre;
    }
    

    and arranged some JavaScript to set the firefox class on the body tag when running with Firefox. However, it doesn’t have the desired effect: can anyone tell me what I might be doing wrong? According to the Firefox debug console, the rule is being applied.

    Rule applied

    Here’s a pen which demonstrates:

    https://codepen.io/vsajip/pen/ppXQeg

    #266045
    Shikkediel
    Participant

    The input element can’t contain pseudos…

    https://stackoverflow.com/q/2587669/3168107

    #266081
    vsajip
    Participant

    Thanks very much. I didn’t get this from reading the documentation on ::after, but I see I should have read the W3C spec. The link you posted is very helpful.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘CSS’ is closed to new topics and replies.