L
L
Legal Adviser2020-05-11 11:53:30
css
Legal Adviser, 2020-05-11 11:53:30

Can css be made into an array?

Hello.
There are several pages on the site that display the styles of the same block.

.nonebefore .blanks a:before,
.nonebefore .zakoni a:before,
.nonebefore .sud_arbitr a:before,
.nonebefore .sud_msk a:before,
.nonebefore .mfc a:before,
.nonebefore .zags_msk a:before,
.nonebefore .notary_msk a:before,
.nonebefore .notary_mo a:before,
.nonebefore .court_practice a:before{
    content: none;
}

On each page, the .nonebefore class changes to something else, say .aaa / .bbb.
Question:
Is it possible to do something like:
.nonebefore, .aaa, .bbb {
.blanks a:before,
.zakoni a:before,
.sud_arbitr a:before,
.sud_msk a:before,
.mfc a:before,
.zags_msk a:before,
.notary_msk a:before,
.notary_mo a:before,
.court_practice a:before{
    content: none;
}
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene Chefranov, 2020-05-11
@Legal2019

If the names of the parent classes are similar, then you can do this:

Will be applied to elements whose class starts withmyClass

H
hzzzzl, 2020-05-11
@hzzzzl

I don't know about pseudo-elements if they will work, but

function addStyleToHead(c) {
  var css = `${c} .blanks a:before,
    ${c} .zakoni a:before,
    ${c} .sud_arbitr a:before,
    ${c} .sud_msk a:before,
    ${c} .mfc a:before,
    ${c} .zags_msk a:before,
    ${c} .notary_msk a:before,
    ${c} .notary_mo a:before,
    ${c} .court_practice a:before{
        content: none;
    }`,
      head = document.head || document.getElementsByTagName('head')[0],
      style = document.createElement('style');

  head.appendChild(style);

  style.type = 'text/css';
  if (style.styleSheet){
    // This is required for IE8 and below.
    style.styleSheet.cssText = css;
  } else {
    style.appendChild(document.createTextNode(css));
  }
}

addStyleToHead('.bbb')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question