Forums

This topic contains 2 replies, has 3 voices, and was last updated by  Shikkediel 11 months, 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #266772

    sobhan konari
    Participant

    hi guys.
    is impossible to change a property value in style.css by search and replace.
    for ex . I want to change width of a psudo element dynamicly.

    span:after{
            content:"";
        top:0;
        left:0;
        position: absolute;
            background-color:red;
            height:20px;
           width:0;
    }
    
    

    and this is the best practice.or website maybe slow.

    thanks.

    #266777

    Paulie_D
    Moderator

    Pseudo-elements can’t be selected by JS as the aren’t in the DOM.

    Frankly, I’m not entirely sure what it is you are trying to do but changing the CSS stylesheet would require a regex parse I think.

    These things are usually handled by changing classes and affecting the pseudo-elements that way.

    #266783

    Shikkediel
    Participant

    Pseudos can be selected with JS (which I didn’t realise until shortly) but are only readable. Changing their properties isn’t possible. What you would be looking for is this:

    https://developer.mozilla.org/en-US/docs/Web/API/CSSRule

    Like Paulie mentioned, the script will need to use a regex and go through the entire stylesheet to find a match. Both the external accessing of the file and especially this search will certainly be a slow and “intensive” approach.

    An example, I found it quite complicated:

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star