Skip to main content

Astro

Build static sites with Ravenbright CSS & Astro. Check out the full demo on Ravenbright CSS Github repo.

View demo
info

Make sure that you already have installed Node.js & npm CLI. read about this on npm official docs

Install Astro​

Step 1: create Astro project​

Create your folder & run this command bellow to follow the Astro built-in installation process on your CLI

npm create astro@latest

Step 2: run the Astro project​

After it's finished, access the project folder & type npm run dev to start the server

cd project
npm run dev

Step 3: understand Astro files & directory structure​

  • src/* - The folder which contains components, CSS, layout & Astro pages
  • public/* - The folder which contains static & unprocessed assets (images, favicon, etc)
  • astro.config.mjs - Astro config file
  • tsconfig.json - TypeScript config file
├── src/
│ ├── components/
│ │ └── Header.astro
│ ├── layouts/
│ │ └── Layout.astro
│ └── pages/
│ │ └── index.astro
│ └── styles/
│ └── global.css
├── public/
│ ├── robots.txt
├── astro.config.mjs
├── package.json
└── tsconfig.json

Global CSS​

Step 1: download or install Ravenbright​

Quickly download Ravenbright source code & copy the CSS into your project folder.

Download source code

or run this command below:

AstroDirectory/
npm install ravenbrightcss --save

Step 2: create the CSS folder​

Create a new src/styles directory and put Ravenbright CSS file into your project directory.

Step 3: import Ravenbright CSS​

Open Layout.astro file which located src/layouts/. Then, import Ravenbright CSS variables file with the following content:

src/layouts/Layout.astro
---
import '../styles/dist/ravenbright.min.css';
---

<html>
<!-- Your page here -->
</html>

Step 4: start using Ravenbright utility classes, components or CSS variables​

Open index.js located in src/pages/. Then write the following content:

src/pages/index.js
---
import Layout from "../layouts/Layout.astro";
---

<Layout>
<main>
<section class="xs-p-y-16 md-p-y-28 bg-gray-50 dark-bg-gray-900">
<div class="container container-xl">
<div class="split-screen items-center">
<div class="flex flex-column xs-m-b-8 md-m-b-0 md-m-r-8 md-width-50">
<h2 class="m-b-6 font-semibold">
Focus on the business & the users
</h2>
<!--advantages-->
<div class="flex flex-column m-b-8">
<div class="flex items-center m-b-4">
<svg
xmlns="http://www.w3.org/2000/svg"
width="22"
height="22"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="ai ai-Check m-r-3 color-blue-600 dark-color-blue-300"
>
<title>Agency case study blog item icon</title>
<path d="M4 12l6 6L20 6"></path>
</svg>
<p>
Start from user research to bring the best product experience
</p>
</div>
<div class="flex items-center m-b-4">
<svg
xmlns="http://www.w3.org/2000/svg"
width="22"
height="22"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="ai ai-Check m-r-3 color-blue-600 dark-color-blue-300"
>
<path d="M4 12l6 6L20 6"></path>
</svg>
<p>
Continuously work together with CLIents to deliver satisfying
results
</p>
</div>
<div class="flex items-center">
<svg
xmlns="http://www.w3.org/2000/svg"
width="22"
height="22"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="ai ai-Check m-r-3 color-blue-600 dark-color-blue-300"
>
<title>Agency case study blog item icon</title>
<path d="M4 12l6 6L20 6"></path>
</svg>
<p>
Group of skilled designers & developers without bureaucratic
hurdles
</p>
</div>
</div>
<a
href="#0"
class="btn dark-bg-blue-500 btn-lg shadow-lg"
role="button"
aria-label="Download Astro template"
>
Download Astro template
</a>
</div>
<img
class="border-radius-md m-b-6 md-width-50 height-100"
src="https://images.unsplash.com/photo-1543269865-cbf427effbad?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxjb2xsZWN0aW9uLXBhZ2V8N3xONWRTdW9qMU9GTXx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=560&q=60"
loading="lazy"
width="560"
alt="Business & work -
Unsplash image by @brookecagle -
https://unsplash.com/photos/-uHVRvDr7pg"
/>
</div>
</div>
</section>
</main>
</Layout>

🎉 It's a wrap! You can check the new section built with Ravenbright in http:localhost://3000 👈 to see the updates.

Component-based CSS​

In this tutorial, we want to create a button component using Ravenbright CSS library in Astro.

Step 1: create button component​

Create a new button.astro component in src/components/.

src/components/button.astro
---
export interface Props {
href: string;
text: string;
}
const { href, text } = Astro.props;
---

<a class="btn w-fit" role="button" href="{href}"> {text} </a>

Step 2: write the CSS inside the component​

Write the CSS inside <style> tag in button.astro. Put Ravenbright CSS variables, components, or utility classes inside <style> tag

src/components/button.astro
<style>
.btn {
--rbrh-green-700: #007c32;
--rbrh-spacing-4: 0.75rem;
--rbrh-spacing-5: 1rem;
--rbrh-radius-md: 0.75rem;
--rbrh-radius-sm: 0.5rem;
--rbrh-radius-xs: 0.25rem;
--rbrh-shadow-xs: 0 0.125rem 0.625rem -0.375rem rgba(0, 0, 0, 0.1), 0px
0.25rem 0.75rem -0.125rem rgba(0, 0, 0, 0.1);

background: var(--rbrh-green-700);
color: white;
border-radius: var(--rbrh-radius-sm);
box-shadow: var(--rbrh-shadow-xs);
padding: var(--rbrh-spacing-4) var(--rbrh-spacing-5);
text-decoration: none;
margin: var(--rbrh-spacing-4) 0;
}
.w-fit {
width: fit-content;
}
.w-100 {
width: 100%;
}
</style>

Step 3: import button into index.js​

Open index.js which located in src/pages/ then import the button component & it's done 🥳.

src/pages/index.js
---
import Button from '../components/Button.astro';
---

<Layout title="Welcome to Astro.">
<main>
<Button href="https://Ravenbrightcss.com" text="Get started with Ravenbright CSS" />
</main>
</Layout>

Check the new button built with Ravenbright CSS in http:localhost://3000 👈 to see the updates.