设置“关于”页面的样式
现在你已经有了一个包含有关你的内容的“关于”页面,是时候对其进行样式设置了!
¥Now that you have an About page with content about you, it’s time to style it!
准备好……
-
在单个页面上设置项目的样式
-
使用 CSS 变量
设置单个页面的样式
标题部分 设置单个页面的样式¥Style an individual page
使用 Astro 自己的 <style></style>
标签,你可以设置页面上项目的样式。向这些标签添加属性和指令为你提供了更多样式设置方式。
¥Using Astro’s own <style></style>
tags, you can style items on your page. Adding attributes and directives to these tags gives you even more ways to style.
-
Copy the following code and paste it into
src/pages/about.astro
:Check all three pages in your browser preview.
-
Which color is the page title of:
- Your Home page?
- Your About page?
- Your Blog page?
-
The page with the biggest title text is?
-
-
Add the class name
skill
to the generated<li>
elements on your About page, so you can style them. Your code should now look like this: -
Add the following code to your existing style tag:
-
Visit your About page in your browser again, and verify, through visual inspection or dev tools, that each item in your list of skills is now green and bold.
使用你的第一个 CSS 变量
标题部分 使用你的第一个 CSS 变量¥Use your first CSS variable
Astro <style>
标签还可以使用 define:vars={ {...} }
指令引用 frontmatter 脚本中的任何变量。你可以在代码围栏内定义变量,然后将它们用作样式标签中的 CSS 变量。
¥The Astro <style>
tag can also reference any variables from your frontmatter script using the define:vars={ {...} }
directive. You can define variables within your code fence, then use them as CSS variables in your style tag.
-
Define a
skillColor
variable by adding it to the frontmatter script ofsrc/pages/about.astro
like this: -
Update your existing
<style>
tag below to first define, then use thisskillColor
variable inside double curly braces. -
Check your About page in your browser preview. You should see that the skills are now navy blue, as set by the
skillColor
variable passed to thedefine:vars
directive.
自己尝试一下 - 定义 CSS 变量
标题部分 自己尝试一下 - 定义 CSS 变量¥Try it yourself - Define CSS variables
-
Update the
<style>
tag on your About page so that it matches the one below. -
Add any missing variable definitions in your frontmatter script so that your new
<style>
tag successfully applies these styles to your list of skills:- The text color is navy blue
- The text is bold
- The list items are in all-caps (all uppercase letters)
✅ Show me the code! ✅
清单
标题部分 清单¥Checklist
资源
标题部分 资源¥Resources
Tutorials