You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: original-docs/2015-04-03-css-syntax.md
+24-24Lines changed: 24 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -5,44 +5,44 @@ subtitle: "who{ what: how;}"
5
5
section: css
6
6
---
7
7
8
-
The purpose of CSS is to define the layout _and_ styling of your HTML elements. The syntax is very simple:
8
+
CSS的目的是定义HTML元素的布局和样式。 语法很简单:
9
9
10
10
{% highlight css %}
11
-
/*A CSS rule*/
11
+
/*CSS书写规则*/
12
12
selector{ property: value;}
13
13
{% endhighlight %}
14
14
15
-
You can read that as:
15
+
你可以这样理解它:
16
16
17
17
{% highlight css %}
18
18
who{ what: how;}
19
19
{% endhighlight %}
20
20
21
-
CSS is a 3-part process:
21
+
CSS的语法分为三部分:
22
22
23
-
*the **selector** defines _who_ is targeted, which HTML element(s)
24
-
*the **property** defines _what_ charateristic to alter
25
-
*the **value** defines _how_ to alter that charateristic
23
+
***选择器**定义目标HTML元素
24
+
***属性**定义要更改的特征
25
+
***值**定义如何更改该特性
26
26
27
-
This whole block (selector/property/value) is a **CSS rule**.
27
+
整个代码块(选择器/属性/值)是一个**CSS规范**
28
28
29
-
### Quick example
29
+
### 快速举例
30
30
31
-
Let's say you want to change the color of all your **blockquotes**.
31
+
假设你想改变所有**blockquote**元素的颜色
32
32
33
33
{% highlight html %}
34
34
<blockquote>Something something</blockquote>
35
35
{% endhighlight %}
36
36
37
-
Focus on the **tag name** (and forget about the angle brackets <> and the text). In our case, all that remains is _"blockquote"_. There's a direct relation between the tag name and the selector.
Let's use that in our CSS as a **selector**, and let's apply some styling:
39
+
让我们在CSS中使用它作为选择器,并添加一些样式
40
40
41
41
{% highlight css %}
42
42
blockquote{ background: lightgreen;}
43
43
{% endhighlight %}
44
44
45
-
Interesting. But now, the text color doesn't really match the background color. Let's improve that:
45
+
有趣的是。现在,文字颜色与背景颜色不一致。 让我们改进一下:
46
46
47
47
{% highlight css %}
48
48
blockquote{
@@ -51,12 +51,12 @@ blockquote{
51
51
}
52
52
{% endhighlight %}
53
53
54
-
So 2 things happened:
54
+
所以发生了两件事情:
55
55
56
-
*we added a _second_ property/value pair, while keeping only _one_ selector: you can set as many properties as you want for any set of selectors
57
-
*we put each property/value pair on its _own line_: like in HTML, the **whitespace** isn't important. It's the special characters `{}``:`and`;`that matter. As a result, you can format your CSS as you wish, to make it more readable, as long as its syntax remains valid.
The `<blockquote>` HTML tag is a **block** element. It has an **inline** counterpart: `<q>`. As they both serve the same purpose (but in different contexts), we'd like to style them identically. We could copy-paste the CSS rule and just change the selector, but there is as you would have guessed, a quicker way:
0 commit comments