CSS custom class does not apply as stated

Case example (WixIDE):

@ global.css:
.s-gridDuane9x9-72dpi {
grid-template-columns: 140px 87px min-content … 227px;
grid-template-rows: 140px min-content … 18px;
}

@ frontend / public:

either:
$w.onReady(function () {
$w(“#firstName”).customClassList.add(“s-gridDuane9x9-72dpi”);
});
or:
export function applyClass() {
$w(“#firstName”).customClassList.add(“s-gridDuane9x9-72dpi”);
}

@ DevTools

Working in
Wix Studio Editor & Wix IDE.

What I’m trying to do
Has no effect whatsoever. The custom class is applied in console.log / DevTools, but it’s effect never take place:

(where I find the class applyed)
#SITE_CONTAINER #main_MF#main_MF .css-editing-scope .wixui-s-gridDuane9x9-72dpi
{
grid-template-columns: 140px 87px … 227px;
grid-template-rows: 140px … 18px;
}

(where the class should be applyed)
#comp-mfwi9z2t4 .comp-mfwi9z2t4-container {
box-sizing: border-box;

grid-template-rows: min-content … 1fr … min-content;
grid-template-columns: 116.5px 116.5px … 1fr … min-content;

}

P.S.: I’m asking code-wise (Wix IDE), not editor tutorials.

I’ve already tried with .box and .container (simmilar to .rich-text__text for texts), but not working.

.box applies the custom CSS class to all box element (except the one I need to be applied on… ofc…) even to those that are not associated with “that class“, so it force itself upon…

The custom CSS class to #_id is so confusing to apply… Except a few classes “nothing“ applies on the “element“ it is supposed to be applied, but on other “elements“ not accessible in editor…

I’ve studied wix documentation on CSS that I’m starting to know it by memory, but is too basic…

1 Like

Hi, @Gabriela_Todorut !!

First of all, as a fundamental rule, your CSS should be written in a file called global.css. Then, you need to associate each class name written in that file with the elements you want to apply those classes to. :slightly_smiling_face:

To link a class to an element, go to the editor, select the element, and open the panel from the “Maximize” button at the bottom right. Open the “CSS Classes” tab, enter the class name you want to apply to the element (in your case, something like s-gridDuane9x9-72dpi) in the “Custom Classes” input field, and press Enter.

If you want to add multiple classes, simply type another class name in the same way and press Enter again to add it. :raising_hands:

Hi, @onemoretime ,

Thank you, I know that, but has nothing to do with what I asked.
I know the editor in and out and it’s not useful for what I need. I’m asking code-wise.

It has to do (and in strong ties) with dynamic codes, not editor tutorials.

Sorry, I skimmed through it without translating it into Japanese and answered right away. Are you trying to check the element’s real ID using the browser’s developer tools and then apply CSS to it? :innocent:

Already tried that too.

  1. That is not good. The class must not be tied to 1 element strict, hence trying to do that in code would be dumb while one can do that in editor.

  2. (though useless) Not even that is working.

The CSS class must not be element-bound but appliable on the wanted targets.
It’s like clothes / skins etc…

The problem is that in wix logic the “element“‘s gird is a totally different “element“ than the “element“ the grid is applied on… and that is a nightmare.

I’m trying to apply a custom CSS class on a code-targeted DOM element. …and it applies.. but container !== it’s own grid


Right, even if you find a solution through DevTools and it happens to work temporarily, there’s no guarantee it will keep working in the long run, so it’s better to avoid relying on that approach. :relieved_face:
You mentioned trying patterns similar to .rich-text__text, but in this case, I think it would be best to ask someone (@noahlovell) from Wix whether there is an official, recommended way to apply grid layouts. :raising_hands:

1 Like

exactly! I need the “wix class“ and not the element’s _id.

On the other side, the “grid mechanism“ should not be “time fragile“ hence there are a ton of websites that have containers with grids for years… It should be a stabile mechanism.

When working with CSS in Wix Studio, you generally need to work alongside the semantic classes provided.

For example, to apply styling to all text elements, you’d do:

.rich-text__text {
  /* styling goes here */
}

If you want to apply something to a specific element, you’ll combine it with a custom class:

.my-custom-class .rich-text__text {
  /* styling goes here */
}

I’d recommend against using the classes applied in the live site, as they’re not guaranteed to remain static and may change over time.


All that said, it’s not 100% clear what the aim is here. Are you able to expand on the end goal so we can advise appropriately?

When working (alongside the semantic classes provided) with CSS in Wix Studio, generally won’t work at all (at least not intuitively or as stated in wix documentation):

I’ve tried it all: .image , .img, etc… nada.
The solution was to ditch it all: cancel the image border and simply work with the “casing“ border, width and color and hide the overflow of it (aka the DOM element available in editor).

… with or without “semantic classes provided“ (except “.rich-text__text“) is the same thing. Either it doesn’t work at all, or there is less than poor documentation on the matter at hand.

The documentation so far is more like going to the dentist with a severe toothache and all you get are 5 y.o. “tutorials“ on how to bush your teeth, as if you’ve never done that ever before. It’s frustrating.

Example as to show that I’m not exaggerating:

The task: I want to dictate the vector image and its color via (a dynamic) code:

  • Wix documentation:
    .vector-image {
    stroke: black;
    stroke-width: 2px;
    filter: hue-rotate(45deg) opacity(0.65);
    width: 150px;
    } … and that’s it.

  • Wix link to: MDN CSS reference docs. is very useful, but it’s like reading a whole human anatomy compendium in order to pull a splinter out of your thumb, besides that “it lists not“ the wix’ “.puppet__elements“ (for obvious reasons… WIX IDE !== MDN CSS).

I’ve already gone in the last 6 months from a complete-code-illiterate & code-uninterested to writing my own +20k lines of code that works (depends how you count them), both backend and frontend (and CSS classes), building a variable-criteria dynamic-infrastructure (aka “skins“), plus a (created from scratch) multi-sheet complex google sheets table-tool that helps me write hundreds of code-lines via a “more-human interface for coding“, and I would def. wish not to spend my next 6 months learning full-stack development just to paint my icons red…

I consider myself still a code-noob, even though now I understand much of it, my project is already 90% done and I just need a little help with the non-intuitive parts, like for the things mentioned above (icon color, even the icons via icon URL is also not working, or I don’t know the “semantic classes provided“ hence those mentioned in the editor, bottom right, CSS class tab, don’t work), … at least not intuitively.

… so I kindly ask for proper help on this matter. At lest point me to the right documentation if the knowledge I lack would require a ton of text, just please no more “5 y.o. tutorials on how to bush my teeth”.

So…:

adding to the css class: .vector-image , .vector-image__ color / fill / stroke / whatever, doesn’t help.

examples of my CSS classes:

  1. .d-artEmailIconDuane (w/o .vector-image…) {
    background-image: url(‘wix:vector://v1/11062b_ff0f0d3f2ca344f39bfd016a693ce18e.svg/Mail%20outline.svg’);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    }
    … to dictate the vector (svg image from wix database, via url) that I want for this “icon“

  2. .c-fill-DefaultDark (w/o .vector-image…) {fill: #4D4D4D;}
    … to dictate the color that I want for this “icon“

Another very confusing pain in the… “backend“ are grids!!! Because the grid of an element created in the Wix Studio !== the actual grid of child-elements placed in “that grid“… . In the DevTool, I can see “MyGrid“ but the stuff that populates this grid, actually populate another grid-element to which I don’t have access to in the Studio… .

How do I super-impose / overwrite via custom CSS Class the grid settings that I actually need over the wix-ghost-elements that actually hold the child-elements? “!important“ is completely useless… .

And above this, by placing an element in the last column of a grid via CSS Class, actually puts that element after / outside the grid instead of “the last column“, and pushes the grid to the left… . so in a 9x9 grid, I have to place the item in the 8th column and make the 9th min-c in order to “visually occupy the right-most part of the grid“.

So as an update for the color of the “icons“:

I’ve found out that in order for the color to be applied i have to write it like this:

.c-fill-DefaultDark {–fill: #4D4D4D;}
with a “–“ (double minus/hyphen) in front of the property.

But I still can’t find how to change / dictate the svg to be shown for the icon via wix image url…

Also, the vector/svg image URL provided by wix result in 400 error: Bad Request…

changing the bad url with another:
background-image: url(https://static.wixstatic.com/shapes/6b8512_1d04386….svg);
… will rezult in:

  • the new svg will be laid over the “normal icon”
  • will not inherit the right color
  • the normal icon still visible under it.

So the questions would be
(all via code & CSS Classes only, I’m not asking for editor tutorials on “how to add a shape to your website“):

  1. How to obtain the svg’s url @ wix database (vectors and/or basic shapes).
  2. How to apply these svg.s (as in replacing the existing ones) on the targeted elements.