Anki CSS/HTML 垂直对齐底部/中心/顶部

Anki CSS/HTML align vertically to bottom / center / top

我正在编辑 Anki deck, which uses HTML and CSS. What I would like to do here is on the front side, vertically aligning the Japanese character to the middle and the hint to the bottom. I tried manually spacing everything with <br>, but then it doesn't work in different resolution windows (and is just a dirty solution) Front example 的模板。

在背面我想让笔划图总是对齐到顶部,带有关键字和助记符的日语字符在中间,其余的在底部。如果我尝试用 <br> 间隔它,我会遇到与首页相同的问题,而且助记符有时是 1 行,但也可以是 5 行以上,所以它必须动态对齐才能工作,即使window 大小始终相同 Back example with arrows。

我已经找到了 this 问题,它似乎在一定程度上回答了我的问题,但由于我对 CSS/HTML 几乎一无所知,所以我不知道如何在我的案例中应用它。如果你能帮助我,我将不胜感激,因为我花了很多时间在这个平台上,它一直让我很烦,我也会分享改进的版本供其他人使用。

这是前面的代码

<div class="front" lang="ja">


<span class="large japanese">{{kanji}}</span>

<br>
<hr>


{{hint:Memory palace}}
返回

<div class="back" lang="ja">
{{strokeDiagram}}<br> <br>
 <hr> 
 <span class="medium"><a href="http://jisho.org/kanji/details/{{kanji}}">{{keyword}}</a></span>
 <br/><br/>
 
<span class="large japanese">{{kanji}}</span>

<br> 
<span class="medium">{{myStory}}</span>  <br><hr> 
<span class="tiny"> Memory palace: {{Memory palace}}</span>


<span class="tiny"> &nbsp; Frame: {{frameNoV6}} &nbsp; Strokes: {{strokeCount}} &nbsp; &mdash; &nbsp; Jouyou Grade: {{jouYou}} &nbsp; JLPT: {{jlpt}}</span><br/>

<!-- Uncomment for Heisig Story          
<hr>
 <span class="medium">{{heisigStory}}</span>
 {{#heisigComment}}<br/><br/><span class="small">{{heisigComment}}</span>{{/heisigComment}}
-->

<!-- Uncomment for koohi Story
<hr/>
 <span class="medium">{{koohiiStory1}}</span>

-->

<hr/>
 <br> <br>
<!-- Uncomment for On-Yomi and Kun-Yomi
 <span class="small">On-Yomi: <span class="medium japanese">{{onYomi}}</span> &nbsp; Kun-Yomi: <span class="medium japanese">{{kunYomi}}</span></span><br/>
-->
<span class="tiny"><a href="http://kanji.koohii.com/study/kanji/{{kanji}}">Constituents:</a> {{constituent}}</span><br/><br/>
 {{#readingExamples}}<span class="tiny">Examples: <span class="japanese">{{readingExamples}}</span></span>{{/readingExamples}}
</div>
和造型,

div.front, div.back {
 text-align: center;
 font-family: sans-serif;
 font-size: 16px; /* line height is based on this size in Anki for some reason, so start with the smallest size used */

}


span.tiny {font-size: 16px;}
span.small {font-size: 24px;}
span.medium {font-size: 32px;}
span.large {font-size: 96px;}
span.italic {font-style: italic;}

.win .japanese {font-family: "Meiryo", "MS Mincho";}
.mac .japanese {font-family: "Hiragino Mincho Pro";}
.linux .japanese {font-family: "Kochi Mincho";}
.mobile .japanese {font-family: "Motoya L Cedar", "Motoya L Maru", "DroidSansJapanese", "Hiragino Mincho ProN";}

前面

div.front,
div.back {
  width: 100%;
  text-align: center;
  font-family: sans-serif;
  font-size: 16px;
  /* line height is based on this size in Anki for some reason, so start with the smallest size used */
}

span.tiny {
  font-size: 16px;
}

span.small {
  font-size: 24px;
}

span.medium {
  font-size: 32px;
}

span.large {
  font-size: 96px;
}

span.italic {
  font-style: italic;
}

.win .japanese {
  font-family: "Meiryo", "MS Mincho";
}

.mac .japanese {
  font-family: "Hiragino Mincho Pro";
}

.linux .japanese {
  font-family: "Kochi Mincho";
}

.mobile .japanese {
  font-family: "Motoya L Cedar", "Motoya L Maru", "DroidSansJapanese", "Hiragino Mincho ProN";
}


/* Positional */

.bottom {
  display: block;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
}

.center {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  /* I want a better way to do the below! */
  top: 50%;
  transform: translateY(-50%);
}

.top {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}
<div class="front" lang="ja">


  <span class="large japanese center">{{kanji}}</span>

  <hr>


  <span class="bottom">{{hint:Memory palace}}</span>

请注意 <hr> 未设置样式。

返回

div.front,
div.back {
  width: 100%;
  text-align: center;
  font-family: sans-serif;
  font-size: 16px;
  /* line height is based on this size in Anki for some reason, so start with the smallest size used */
}

span.tiny {
  font-size: 16px;
}

span.small {
  font-size: 24px;
}

span.medium {
  font-size: 32px;
}

span.large {
  font-size: 96px;
}

span.italic {
  font-style: italic;
}

.win .japanese {
  font-family: "Meiryo", "MS Mincho";
}

.mac .japanese {
  font-family: "Hiragino Mincho Pro";
}

.linux .japanese {
  font-family: "Kochi Mincho";
}

.mobile .japanese {
  font-family: "Motoya L Cedar", "Motoya L Maru", "DroidSansJapanese", "Hiragino Mincho ProN";
}


/* Positional */

.bottom {
  display: block;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
}

.center {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  /* I want a better way to do the below! */
  top: 50%;
  transform: translateY(-50%);
}

.top {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}
<div class="back" lang="ja">
  <div class="top">{{strokeDiagram}}</div>
  <hr>
  <div class="center"><span class="medium"><a href="http://jisho.org/kanji/details/{{kanji}}">{{keyword}}</a></span>

    <span class="large japanese">{{kanji}}</span>
  </div>

  <div class="bottom">
    <span class="medium">{{myStory}}</span> <br>
    <hr>
    <span class="tiny"> Memory palace: {{Memory palace}}</span>


    <span class="tiny"> &nbsp; Frame: {{frameNoV6}} &nbsp; Strokes: {{strokeCount}} &nbsp; &mdash; &nbsp; Jouyou Grade: {{jouYou}} &nbsp; JLPT: {{jlpt}}</span><br/>

    <!-- Uncomment for Heisig Story          
<hr>
 <span class="medium">{{heisigStory}}</span>
 {{#heisigComment}}<br/><br/><span class="small">{{heisigComment}}</span>{{/heisigComment}}
-->

    <!-- Uncomment for koohi Story
<hr/>
 <span class="medium">{{koohiiStory1}}</span>

-->

    <hr/>
    <br> <br>
    <!-- Uncomment for On-Yomi and Kun-Yomi
 <span class="small">On-Yomi: <span class="medium japanese">{{onYomi}}</span> &nbsp; Kun-Yomi: <span class="medium japanese">{{kunYomi}}</span></span><br/>
-->
    <span class="tiny"><a href="http://kanji.koohii.com/study/kanji/{{kanji}}">Constituents:</a> {{constituent}}</span><br/><br/> {{#readingExamples}}
    <span class="tiny">Examples: <span class="japanese">{{readingExamples}}</span></span>{{/readingExamples}}
  </div>
</div>

此技术的一个问题是,如果 space 不足,它们将相互覆盖。