创建一个通用的货币符号混合项,适用于任何【小】文本。

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

Create a general currency symbol mixin for any [small] text

问题

我需要在正在构建的网站上显示不同位置的一些价格。为此,我创建了一个sass混合,应该有助于在价格前面创建我想要的货币符号,并使用较小的font-size。下面显示了价格应该看起来的样子以及我的混合的示例。

我的混合:

@mixin add-currency($symbol: "R$") {
  margin-left: 17px;
  position: relative;
  &::before {
    bottom: 0px;
    content: $symbol;
    @include s.font(12);
    left: -17px;
    position: absolute;
  }
}

我的价格应该是这样的:

创建一个通用的货币符号混合项,适用于任何【小】文本。

如你所见,货币符号应该与数字的基线对齐,但在某些情况下,符号会与逗号的最底部对齐,就像这样:

创建一个通用的货币符号混合项,适用于任何【小】文本。

创建一个通用的货币符号混合项,适用于任何【小】文本。

对于上面的示例,在符号未正确对齐的情况下,它们的css如下:

第一个错误示例:

color: #1e273a;
font-family: "Roboto";
font-size: 1rem;
font-weight: 500;
line-height: 1.3333333333rem;
margin-left: 17px;
position: relative;

第二个错误示例:

margin-left: 17px;
position: relative;
font-family: "Roboto";
font-size: 1.5625rem;
font-weight: 600;
line-height: 2.0833333333rem;

我还没有找到上述示例中可能导致货币符号对齐不准确的原因,也没有找到纠正这个问题的方法。我的混合背后的想法是使其能够轻松地将其添加到任何[小]文本中,并添加所选的货币符号,尽管我知道它不会适用于每种可能的情况,但我相信对于这两种情况,我的混合应该有效,对吗?

谢谢您的关注 创建一个通用的货币符号混合项,适用于任何【小】文本。

英文:

I have to show some prices in different places on a site I am building. For that, I created a sass mixin that should help to create the currency symbol I want before the price and with a smaller font-size. An example of what the prices should look like and how my mixin ended up are shown below.

My mixin:

@mixin add-currency($symbol: "R$") {
  margin-left: 17px;
  position: relative;
  &::before {
    bottom: 0px;
    content: $symbol;
    @include s.font(12);
    left: -17px;
    position: absolute;
  }
}

How my prices should look like:

创建一个通用的货币符号混合项,适用于任何【小】文本。

As you can see, the currency symbol should be aligned with the baseline of the number, but in some cases the symbol ends up aligned with the bottom-most point of the comma, like this:

创建一个通用的货币符号混合项,适用于任何【小】文本。

创建一个通用的货币符号混合项,适用于任何【小】文本。

For the examples above, where the symbol isn't properly aligned, their css look like this:

First wrong example:

color: #1e273a;
font-family: "Roboto";
font-size: 1rem;
font-weight: 500;
line-height: 1.3333333333rem;
margin-left: 17px;
position: relative;

Second wrong example:

margin-left: 17px;
position: relative;
font-family: "Roboto";
font-size: 1.5625rem;
font-weight: 600;
line-height: 2.0833333333rem;

I haven't found what, in the examples above, could be leading to this misalignment in the currency symbol, and also haven't found a way to correct this. The ideia behind my mixin is to make possible to just add this to any [small] text and add to it the chosen currency symbol, and although I know it won't work for every possible case, I believe for these two cases my mixin should work, right?

Thanks in advance for your attention 创建一个通用的货币符号混合项,适用于任何【小】文本。

答案1

得分: 1

您的Mixin中的货币符号可能因符号和定价文本之间的line-height差异而不对齐。

如果我们有解决line-height的解决方案,那么我们将会有解决方案:

也许使用inherit属性调整line-height将解决这个问题。

@mixin add-currency($symbol: "R$") {
  margin-left: 17px;
  position: relative;
  &::before {
    bottom: 0;
    content: $symbol;
    @include s.font(12);
    left: -17px;
    position: absolute;
    line-height: inherit; 
  }
}
英文:

The currency symbol in your mixin may be misaligned due to the difference in line-height between the symbol and the pricing text.

If we have the solution for that line-height fixing we will be having the solution then:

Might be that adjustment of line-height with inherit property will solve the issue.

@mixin add-currency($symbol: "R$") {
  margin-left: 17px;
  position: relative;
  &::before {
    bottom: 0;
    content: $symbol;
    @include s.font(12);
    left: -17px;
    position: absolute;
    line-height: inherit; 
  }
}

huangapple
  • 本文由 发表于 2023年7月7日 01:44:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76631347.html
匿名

发表评论

匿名网友

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

确定