Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS 小妙招:CSS 变量 —— 如何轻松创建一个🌞白色/🌑暗色主题 #6433

Conversation

eizyc
Copy link
Contributor

@eizyc eizyc commented Oct 13, 2019

第一次翻译完成

译文翻译完成,resolve #6424

@Reaper622
Copy link
Contributor

@fanyijihua 校对认领

@fanyijihua
Copy link
Collaborator

@Reaper622 好的呢 🍺

@sleepingxixi
Copy link

sleepingxixi commented Oct 13, 2019

@Glowin 校对认领
@fanyijihua 校对认领

Reaper622
Reaper622 previously approved these changes Oct 13, 2019
Copy link
Contributor

@Reaper622 Reaper622 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整体翻译的不错,提出了一点修改建议。: )
校对完成 @cyz980908 @fanyijihua


Maybe you wanted to implement a dark theme? It was possible, but now it has become easier!
又或许您想实现一个暗色的主题?这些都是可以实现的,但现在变得容易了。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「又或许你想实现一个暗色的主题」 => 「又或许你想实现一个黑夜模式」


Finally! If you ever have worked with CSS and wanted to keep your design consistent? Or was it more like at some pages, your website had different padding, margin or colors?
终于来了。如果您曾经写过 CSS,并且想完美还原设计稿?或者还想在某些页面上,让你的网站有不同的填充、边距或颜色?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「终于来了。」 => 「废话不多说,我们进入主题」

Finally 在口语化中在开头一般表示 寒暄结束,进入主题,此处翻译为终于的意味,不妥当。


Let's have a look at it!
来吧!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「来吧」 => 「让我们先睹为快!」


Okay, the rest is pretty simple. The custom property `--example-color` has the value of `#ccc`. When we use the custom property, for example, on the `background-color` property, the background of that element will be a light gray. Cool right?
好啦,那剩下的就很简单了。自定义属性 `--example-color` 的值为 `#ccc`。当我们使用自定义属性时,如 `background-color`,元素的背景将是浅灰色。酷吧?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「当我们使用自定义属性时,如 background-color」 => 「当我们在例如background-color的属性上使用自定义属性」


For this, we need to learn the `var()` function.
The `var()` can have two arguments. The first argument needs to be a custom property. If the custom property is not valid, you want to have a fallback value. To achieve this, you simply need to set the second argument of the `var()` function. Let's look at an example.
首先,我们需要学习 var() 函数。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var() 应该保持原来的格式吧,var()

@@ -63,37 +63,37 @@ The `var()` can have two arguments. The first argument needs to be a custom prop
}
```

This should be now pretty straightforward for you to understand. We are setting the `--example-color` to `#ccc` and then we are using it in `.someElement` to set the background color. If something goes wrong and our `--example-color` is not valid, we have a fallback value of `#d1d1d1`.
现在你们应该很容易理解了。我们将 `--example-color` 设置为 `#ccc`,然后在 `.someElement` 中使用它来作为背景颜色。 如果出了问题,我们的 `--example-color` 将失效,那么我们的回退值为 `#d1d1d1`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「如果出了问题,我们的 --example-color 将失效」=>「如果出了一些问题,使我们的--example-color 失效了」


Let's first have a look at what we will do here:
首先我们先来看看我们要达到什么效果:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「首先我们先来看看我们要达到什么效果」=>「先来看看我们我们即将做的事:」


Since this code is lengthy, I will show it to you step by step!
因为这段代码很长,所以我将一步一步地带你来写!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「因为这段代码很长,所以我将一步一步地带你来写」 =>「因为这段代码很长,所以我将一步一步地分解」

@@ -229,7 +229,7 @@ Here comes an integral part of the code. We now see why we named the `.theme-con
}
```

This is just some boilerplate code to set our style. In the `.demo` selector, we are setting the `font-size`. This is the size of our symbols for the toggle. In the `.switch` selector the `height` and `width` is how long and wide the element behind our toggle symbol is.
这只是一些样例代码来设置我们的样式。在 `.demo` 选择器中,我们设置 `font-size` 给切换符号的大小。在 `.switch` 选择器中,`height` `width` 是切换符号后面的元素的长度和宽度。

```
/* The slider */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -262,7 +262,7 @@ This is just some boilerplate code to set our style. In the `.demo` selector, we
}
```

Here we can finally see our custom properties in action besides using them directly in the `.theme.container` and again a lot of boilerplate code. As you can see, the toggle symbols are simple Unicode symbols. This is why the toggle will look different on every OS and mobile phone vendor. You have to keep this in mind. Important to know here is that in the `.slider:before` Selector, we are moving our symbol around with the `left` and `top` properties. We are doing that also in the `.theme-switcher:checked + .slider:before` but only with the `left` property.
到这里,除非你直接在 `.theme.container` 中设定了自定义属性,或者写了其他的代码,那么现在我们终于可以看到自定义属性的效果了。正如你所看到的,切换符号是简单的 Unicode 字符。这就是为什么切换开关在不同的操作系统和手机系统上看起来会不同的原因,这一点你需要注意。还需要注意的是,在 `.slider:before` 选择器中,我们使用 `left` `top` 属性来移动符号。我们在 `.theme-switcher:checked + .slider:before` 中也这样做了,但只使用了 `left` 属性。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句话看起来有点怪怪的。
「到这里,除非你直接在 .theme.container 中设定了自定义属性,或者写了其他的代码,那么现在我们终于可以看到自定义属性的效果了。」=>「现在我们终于可以看到自定义属性的效果,排除你直接在 .theme.container 中设定了自定义属性,或者写了其他的代码的情况」

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得改完还是很怪...

@@ -262,7 +262,7 @@ This is just some boilerplate code to set our style. In the `.demo` selector, we
}
```

Here we can finally see our custom properties in action besides using them directly in the `.theme.container` and again a lot of boilerplate code. As you can see, the toggle symbols are simple Unicode symbols. This is why the toggle will look different on every OS and mobile phone vendor. You have to keep this in mind. Important to know here is that in the `.slider:before` Selector, we are moving our symbol around with the `left` and `top` properties. We are doing that also in the `.theme-switcher:checked + .slider:before` but only with the `left` property.
到这里,除非你直接在 `.theme.container` 中设定了自定义属性,或者写了其他的代码,那么现在我们终于可以看到自定义属性的效果了。正如你所看到的,切换符号是简单的 Unicode 字符。这就是为什么切换开关在不同的操作系统和手机系统上看起来会不同的原因,这一点你需要注意。还需要注意的是,在 `.slider:before` 选择器中,我们使用 `left` `top` 属性来移动符号。我们在 `.theme-switcher:checked + .slider:before` 中也这样做了,但只使用了 `left` 属性。

```
/* Rounded sliders */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> * 校对者:

# CSS Quickies: CSS Variables - Or how you create a 🌞white/🌑dark theme easily
# CSS 速战速决:CSS 变量 —— 如何轻松创建一个🌞白色/🌑暗色主题

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个css quickies翻译成css速战速决感觉有点奇怪,我特地上网查一下有没有更好的解释,我通过必应翻译得到的是css 速效,感觉这个好像更符合一些,但是这个说法也有点奇怪。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你可能不知道的 CSS怎么样
Quickies:速战速决;便利贴;你可能不知道

sleepingxixi
sleepingxixi previously approved these changes Oct 13, 2019
Copy link

@sleepingxixi sleepingxixi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实翻译挺好的,只是感觉题目这块可以再斟酌一下,还有一下小地方再修改一下哈。
@cyz980908 @Glowin 校对完成

@@ -5,15 +5,15 @@
> * 译者:[cyz980908](https://github.com/cyz980908)
> * 校对者:[Reaper622](https://github.com/Reaper622),[sleepingxixi](https://github.com/sleepingxixi)

# CSS 速战速决:CSS 变量 —— 如何轻松创建一个🌞白色/🌑暗色主题
# 你不知道的 CSS:CSS 变量 —— 如何轻松创建一个🌞白色/🌑暗色主题

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实我还是很纠结这里到底该用什么名字,我刚才问了同事和朋友,他们说这个相当于是技巧,妙招,锦囊之类的,不能直接翻译,那样子太奇怪了。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所以我觉得可以叫css妙招,css技巧,或者css锦囊

element.style.setProperty("--my-color", "#ccc");
```

我们可以像任何其他属性一样获取和设置自定义属性。这还不酷吗?

#### 使用自定义变量实现一个主题切换器

首先我们先来看看我们要达到什么效果
先来看看我们我们即将做的事

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方我刚才写错了,多了一个我们。
「先来看看我们我们即将做的事」=>「先来看看我们即将做的事」

@@ -176,20 +176,20 @@ Since this code is lengthy, I will show it to you step by step!
}
```

Lets first center our content. We are doing this with css `grid`. We will cover the `grid` feature in another CSS quickies!
首先让我们集中内容布局。我们用 CSS 的 `grid` 特性实现。我们将在另一个 CSS 速战速决中介绍 `grid` 特性!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果要修改css quickies的翻译,记得这块也要一起修改哦

感谢校对~辛苦辛苦
@eizyc eizyc changed the title CSS 速战速决:CSS 变量 —— 如何轻松创建一个🌞白色/🌑暗色主题 CSS 小技巧:CSS 变量 —— 如何轻松创建一个🌞白色/🌑暗色主题 Oct 13, 2019
@eizyc eizyc changed the title CSS 小技巧:CSS 变量 —— 如何轻松创建一个🌞白色/🌑暗色主题 CSS 小妙招:CSS 变量 —— 如何轻松创建一个🌞白色/🌑暗色主题 Oct 13, 2019
sleepingxixi
sleepingxixi previously approved these changes Oct 14, 2019
Copy link

@sleepingxixi sleepingxixi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最后一个想提的意见。辛苦译者了

@@ -176,7 +176,7 @@ checkbox.addEventListener("change", function() {
}
```

首先让我们集中内容布局。我们用 CSS 的 `grid` 特性实现。我们将在另一个 CSS 速战速决中介绍 `grid` 特性!
首先让我们集中内容布局。我们用 CSS 的 `grid` 特性实现。我们将在另一个 CSS 小技巧中介绍 `grid` 特性!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「CSS 小技巧」=>「CSS 小妙招」

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

感谢校对~
@JaxNext
Copy link
Contributor

JaxNext commented Oct 14, 2019

@Glowin 校队认领

文字准确有助于标签管理哦。

sleepingxixi
sleepingxixi previously approved these changes Oct 14, 2019
Copy link

@sleepingxixi sleepingxixi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我是真的希望这是最后一次修改了。我不是故意这么较真,但是真的有点强迫症。

根据校对者意见做出修改
@eizyc
Copy link
Contributor Author

eizyc commented Oct 16, 2019

@lsvih 您是工作人员吗?可以帮忙审核一下吗?

@lsvih lsvih added 前端 标注 待管理员 Review labels Oct 16, 2019
@lsvih lsvih self-assigned this Oct 16, 2019
@lsvih
Copy link
Member

lsvih commented Oct 16, 2019

本文 3 分,校对各 1 分

@lsvih
Copy link
Member

lsvih commented Oct 16, 2019

@cyz980908 我修改了一点格式,您记得更新一下本地版本哈。

@lsvih lsvih merged commit 4c229cd into xitu:master Oct 16, 2019
@lsvih
Copy link
Member

lsvih commented Oct 16, 2019

@cyz980908 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。

掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件
专栏地址:https://zhuanlan.zhihu.com/juejinfanyi

@lsvih lsvih added 翻译完成 and removed 标注 待管理员 Review labels Oct 16, 2019
@eizyc
Copy link
Contributor Author

eizyc commented Oct 16, 2019

好的辛苦了谢谢链接在这
https://juejin.im/post/5da6c370e51d4524a0060385

@eizyc
Copy link
Contributor Author

eizyc commented Oct 16, 2019

@lsvih lsvih removed their assignment Jul 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSS 小妙招:CSS 变量 —— 如何轻松创建一个🌞白色/🌑暗色主题
6 participants