英文:
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;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论