Style your About page
本頁內容尚未翻譯。
Now that you have an About page with content about you, it’s time to style it!
Get ready to…
- Style items on a single page
- Use CSS variables
Style an individual page
Section titled Style an individual pageUsing 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?
If you are unable to determine colors visually, you can use the dev tools in your browser to inspect the
<h1>
title elements and verify the text color applied. -
-
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.
Use your first CSS variable
Section titled Use your first CSS variableThe 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.
Try it yourself - Define CSS variables
Section titled 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)