有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

huangapple go评论61阅读模式
英文:

Is there a CSS that can render variable height for each character depending on the height of a character?

问题

以下是代码的部分,不做翻译:

The CSS below,

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.message {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 2rem;
}

<!-- language: lang-html -->

&lt;display class=&#39;message&#39;&gt;ㄨㄢˊ㄄ㄤˇ&lt;/display&gt;

<!-- end snippet -->

produces this output. Notice the space beneath character ˊ:

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

Is there a CSS that can render individual characters based on their height, so that punctuations (e.g., period and comma) and accent characters won't take up space? The word above needs to be displayed as this instead:

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

The above will be used on CSS pseudo elements. Thus, wrapping each character in their own div or span is not feasible.

Problem details are here: zhuyin (bopomo) inconsistently aligned #10

For the question about trying different fonts:

I tried several fonts, and all of them still render accent characters (e.g., ˊ) with space underneath it. All of them basically produces this:

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

Here are all the fonts I've tried:

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

For the answers that advise to embed extra div/span, I need to emphasize as stated in the question that on my specific use case, div/span(any HTML tags for that matter) cannot be embedded in CSS pseudo elements.

As for the rationale for using CSS pseudo elements as an annotation mechanism (instead of say using ruby or combo of div and span), CSS pseudo elements is the only way to annotate text that the Chrome extension will not interfere with browser's copy-paste (i.e., <kbd>Ctrl</kbd> + <kbd>C</kbd>) functionality and on functionality of 3rd-party Chrome extension dictionaries. The Ruby tag is not an option even if it can embed HTML. Ruby interferes too much with the browser's copy-paste and other dictionaries.

Using span and div for annotations will get their content being copied too when highlighting and copying the original text.

Try copying the original text in the link below. If the annotation mechanism is using tech, such as ruby and or div/span, those tags' content will get copied too:

https://www.w3schools.com/code/tryit.asp?filename=G08ZZXDZJ7MX

Annotating text using CSS pseudo elements is the only option for a Chrome extension not to interfere with the browser's copy-paste functionality, and for it not to interfere with other third-party Chrome extensions too.

Here's how CSS pseudo elements is used in the code (Chrome extension) as annotator: Zhuyin (bopomo) intonations not displayed correctly when text is vertically aligned #9

英文:

The CSS below,

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.message {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 2rem;
}

<!-- language: lang-html -->

&lt;display class=&#39;message&#39;&gt;ㄨㄢˊㄇㄢˇ&lt;/display&gt;

<!-- end snippet -->

produces this output. Notice the space beneath character ˊ:

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

Is there a CSS that can render individual characters based on their height, so that punctuations (e.g., period and comma) and accent characters won't take up space? The word above needs to be displayed as this instead:

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

The above will be used on CSS pseudo elements. Thus, wrapping each character in their own div or span is not feasible.

Problem details are here: zhuyin (bopomo) inconsistently aligned #10

For the question about trying different fonts:

I tried several fonts, and all of them still render accent characters (e.g., ˊ) with space underneath it. All of them basically produces this:

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

Here are all the fonts I've tried:

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

For the answers that advises to embed extra div/span, I need to emphasize as stated in the question that on my specific use case, div/span(any HTML tags for that matter) cannot be embedded in CSS pseudo elements.

As for the rationale for using CSS pseudo elements as an annotation mechanism (instead of say using ruby or combo of div and span), CSS pseudo elements is the only way to annotate text that the Chrome extension will not to interfere with browser's copy-paste (i.e., <kbd>Ctrl</kbd> + <kbd>C</kbd>) functionality and on functionality of 3rd-party Chrome extension dictionaries. The Ruby tag is not an option even if it can embed HTML. Ruby interferes too much with the browser's copy-paste and other dictionaries.

Using span and div for annotations will get their content being copied too when highlighting and copying the original text.

Try copying the original text in the link below. If the annotation mechanism is using tech, such as ruby and or div/span, those tags' content will get copied too:

https://www.w3schools.com/code/tryit.asp?filename=G08ZZXDZJ7MX

Annotating text using CSS pseudo elements is the only option for a Chrome extension not to interfere with the browser's copy-paste functionality, and for it not to interfere with other third-party Chrome extensions too.

Here's how CSS pseudo elements is used in the code (Chrome extension) as annotator: Zhuyin (bopomo) intonations not displayed correctly when text is vertically aligned #9

答案1

得分: 0

我可以建议您像这样手动指定需要调整的字符:

<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.message {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 2rem;
}
.accent {
  margin-bottom: -1.8rem;
}
<!-- language: lang-html -->
<display class='message'>ㄨㄢ<span class="accent">ˊ</span>ㄇㄢˇ</display>
<!-- end snippet -->
英文:

I can suggest you something like this by specifying manually which character you need to adjust:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.message {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 2rem;

}
.accent {
  margin-bottom: -1.8rem;
}

<!-- language: lang-html -->

&lt;display class=&#39;message&#39;&gt;ㄨㄢ&lt;span class=&quot;accent&quot;&gt;ˊ&lt;/span&gt;ㄇㄢˇ&lt;/display&gt;

<!-- end snippet -->

答案2

得分: 0

.message {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 2rem;
}
<display class='message'>ㄨㄢˊ㄄ㄢˇ</display>
英文:

<!-- begin snippet: js hide: false console: true babel: null -->

<!-- language: lang-css -->

.message {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 2rem;
}

<!-- language: lang-html -->

&lt;display class=&#39;message&#39;&gt;ㄨㄢˊㄇㄢˇ&lt;/display&gt;

<!-- end snippet -->

答案3

得分: 0

I solved it, and it now looks more centered. It is not perfect though, but it is good enough not to confuse on which word the annotation belongs to.

I went with using a letter-spacing of -0.20em and with the suggestion of Pablo V to use traditional Chinese fonts. Noto Serif TC font is one good choice. The magic mostly comes from Noto Serif TC font.

Before

Take notice of the words , , 故事, and 如何. Their annotation look more top-aligned despite using flex-direction: column-reverse; align-items: center

After

I am still using flex-direction: column-reverse; align-items: center, but with letter-spacing: -0.20em; and font-family: Noto Serif TC.

Take notice of the words , , 故事, and 如何. Their annotations now look more vertically-centered as compared to before.

The letter-spacing -0.20em is not hard coded. The user can choose which font combination and letter-spacing (Guide spacing) gives the best result for them and their eyes.

英文:

I solved it, and it now looks more centered. It is not perfect though, but it is good enough not to confuse on which word the annotation belongs to.

I went with using a letter-spacing of -0.20em and with the suggestion of Pablo V to use traditional Chinese fonts. Noto Serif TC font is one good choice. The magic mostly comes from Noto Serif TC font.

Before

Take notice of the words , , 故事, and 如何. Their annotation look more top-aligned despite using flex-direction: column-reverse; align-items: center

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

After

I am still using flex-direction: column-reverse; align-items: center, but with letter-spacing: -0.20em; and font-family: Noto Serif TC.

Take notice of the words , , 故事, and 如何. Their annotations now look more vertically-centered as compared to before.

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

The letter-spacing -0.20em is not hard coded. The user can choose which font combination and letter-spacing (Guide spacing) gives the best result for them and their eyes.

有没有一种CSS可以根据字符的高度来呈现每个字符的可变高度?

huangapple
  • 本文由 发表于 2023年3月9日 16:28:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75682045.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定