I can't remove margin from card

What is the real class or id I need to modify to reset the card’s CSS margin?
(on all platforms: computer, Anki Droid, etc.).

I couldn’t identify which class this is. As a stopgap measure, I used Reset CSS, but it’s still not enough for me. Reset CSS is the only one that managed to eliminate the margin of this unknown class.

I already tried this and it didn’t work:

html {
margin: 0 !important;
padding: 0 !important;
}
html body {
   margin: 0 !important;
   padding: 0 !important;
}
.card {
   margin: 0 !important;
   padding: 0 !important;
}


With these codes above, the unwanted result is this:


However, when I applied Reset CSS, I was finally able to reset the margin on both PC and AnkiDroid, but it only works with “!important”. But, applying Reset CSS, there is a problem of removing the margin from all elements, even though the margin property is defined on each element. So I’m forced to put in the margin of other elements “!important” too to fix this. Look:

* {
	margin: 0 !important;
}
.front {
   margin-top: 50px !important;
}

Note that if I don’t apply “!important” to other classes, my text from the “front” field is pasted into the header. However, the card margin is corrected:



Full Code Front:

<div class="header">
   <h1>Header<h1>
</div>

<div class="front">{{Front}}</div>


Complete CSS Code:

* {
	margin: 0 !important;
}

.card {
    font-family: arial;
    font-size: 20px;
    text-align: center;
    color: black;
    background-color: #f9c59c;
}

.header {
   background-color: #373737;
   color: #fff;
   padding: 10px;
}

.front {
		margin-top: 50px !important;
}

what does removing the <h1> tags give you? It might be the headers if you didn’t already try changing that.

My problem doesn’t have to do with the <h1> tag, because from the images, you can see that the margin is outside the top .header element.

The problem I face is a default margin in the card template itself that forces this margin on all elements and I want to remove it. I was already able to remove this margin in Anki for Windows, but I was unable to remove it in Anki Droid.

I created a script to view the source code of the page on Anki Droid and I already found out which id has this margin applied. It’s the #content id.

#content {
  margin: 0;
}

I use the following CSS to ensure that a background image fills the entire card.

html, body {margin: 0; height: 100%; overflow: hidden}

I tried adding your header example + css to one of my cards and it seems to accomplish what you’re after.

Of course, YMMV. Good luck.

1 Like

Seems like there’s a solution. About the margin, this is apparently done for readability. [BUG]: Review and Browse have different style · Issue #17058 · ankidroid/Anki-Android · GitHub

Have you tested if your code to remove the margin works on Anki for mobile? For me, html , body {margin: 0;} only works on desktop, but it doesn’t work on Anki for mobile.

I opened the link you sent, from what I understand the author of the github issue wants to customize the Anki mobile previewer itself. I just want to customize the card itself. As I said in my previous message, I already found out which CSS ID the Anki mobile app uses to automatically apply this margin. And now, I’ve managed to remove it both from the desktop and from Anki Mobile.

No I haven’t; I never use mobile. Sorry.

Actually, I never use the mobile app. Hmmm.

No they are talking about the review screen. Look at Brayan’s comment.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.