简体   繁体   English

文本未与大字体对齐

[英]Text not aligning with large font-size

I'm building a periodic table in HTMl/CSS and I cant get the text inside the large .element-symbol to align left with the .atomic-weight , .element-name and .atomic-symbol without an arbitrary text-indent . 我正在HTMl / CSS中构建一个元素周期表,我无法在大的.element-symbol内部获取文本,以便与.atomic-weight.element-name.atomic-symbol而不使用任意text-indent I guess this is just to do with the width of the letters, but is there a way of having the first letter in .element-symbol start hard left? 我想这只是与字母的宽度有关,但有没有办法让.element-symbol中的第一个字母开始用力了? ie against the red border 即对着红色边界

Markup: 标记:

<div class="cell">
  <div class="atomic-number"><span>2</span></div>
  <div class="element-symbol">      
    <abbr>He</abbr>
  </div>
  <div class="element-name"><span>Helium</span></div>
  <div class="atomic-weight">4.002602</div>
  </div>

CSS: (red borders to show alignment issue) CSS :(红色边框显示对齐问题)

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  line-height: 1;
  }

.cell {
  border: 1px solid black;
  font-family: sans-serif;
  width: 280px;
  height: 280px;
  margin: 20px auto;
  padding:10px;
  background-color: #4DBCE9;
  }

.element-symbol {
 font-size: 173px;
 border: 1px solid red;
 font-weight: 400;
 /*text-indent: -12px;  dont want to use this*/
 }

.atomic-number, .atomic-weight, .element-name {
 font-size: 25px;
 border: 1px solid red;
 }

Example in codepen codepen中的示例

Each glyph in a font, sits within a bounding box. 字体中的每个字形都位于边界框内。 The glyph is usually not hard up against any of the edges of that box, and each glyph (or letter) will have differing amounts of space around it to help space it naturally when it is combined with other glyphs to form words. 字形通常不会难以对抗该框的任何边缘,并且每个字形(或字母)周围将具有不同的空间量,以便在与其他字形组合形成单词时自然地使其空间化。

Have a look at http://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html to get a feel for some of the intricacies of type design. 请查看http://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html ,了解一些类型设计的复杂性。

I'm not aware of any text or font properties in CSS that can eliminate that space, and in any case that space will be different for each glyph, and different between the same glyphs in different fonts. 我不知道CSS中可以消除该空间的任何文本或字体属性,并且在任何情况下,每个字形的空间都不同,并且不同字体中的相同字形之间不同。

You're right - it's simply because of the size of the letters. 你是对的 - 这只是因为字母的大小。

In most fonts, each character has a small amount of whitespace to either side of it, to separate it from adjacent letters. 在大多数字体中,每个字符在其两侧都有少量的空格,以将其与相邻字母分开。 Without this space the letters would just run in to each other. 如果没有这个空间,这些字母就会相互碰撞。 At large font sizes, this space gets to be fairly significant, and produces the effect you're seeing. 在较大的字体大小下,这个空间变得非常重要,并产生您所看到的效果。 The only other option would be to find (or create) a font that doesn't have that space (or perhaps only has trailing space after each letter and no leading space). 唯一的另一种选择是找到(或创建)没有该空间的字体(或者每个字母后面只有尾随空格而没有前导空格)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM