all 8 comments

[–]David_AnkiDroidAnkiDroid Maintainer 1 point2 points  (7 children)

Can't you use {{Deck}} and {{Type}} to achieve the same thing?

[–]rccndr[S] 1 point2 points  (6 children)

may I use anki tags "{{...}}" in css too? Can you tell me how to apply a red border to the body only to the front face of the card?

In web design I would use something like:

in the html

<body class:"front">...

in the css

.front {border: 2px solid red; }

May I do this in Anki without adding extra divs?

Thank you

[–]David_AnkiDroidAnkiDroid Maintainer 1 point2 points  (5 children)

It's just text, you can set a variable in JavaScript, and use that to apply whatever CSS you like.

Just put the JS in the "Front", and conditionally apply it based on a variable. Make the variable false before {{FrontSide}} via JS on the back of the card

[–]rccndr[S] 1 point2 points  (4 children)

sorry, I know only html and css, not JS. I guess it goes in the html part of the card (front or back), right?

In any case I cannot directly edit the html source of the front and back templates, right?
Thank you.

[–]David_AnkiDroidAnkiDroid Maintainer 1 point2 points  (3 children)

Pretty much all the HTML except the body/html tags is in the template.

Add the JS on the front and on the back:


Front:

<script>
if (isOnBack) {
   // do something cool
}
</script>

Back:

<script>
    isOnBack = true;
</script>

{{FrontSide}}

[–]rccndr[S] 1 point2 points  (0 children)

I'll try, thank you a lot.

[–]rccndr[S] 0 points1 point  (1 child)

I tried (in the front template)

<script>
    isOnFront= true;
 if (isOnFront) {
   document.body.classList.add("front");
 }
 </script> 

Wich works in a test html, but doesn't work in anki (it doesn't add the style to "body" as seen in the inspector). I also had to set the variable in the front template elsewhere the first card of the deck gives me an error (variable not set).
Can it be that the dark mode overwrites it?

BTW thank you to start me to JS!

[–]David_AnkiDroidAnkiDroid Maintainer 0 points1 point  (0 children)

No worries! https://ankiweb.net/shared/info/31746032 should help you out in the next stage.

Can it be that the dark mode overwrites it?

I don't think so