HannahNguyen6729
Introduction 🥳
===============
App.svelte is our main Svelte fileApp.cssis our main global CSS filelib folder contains our components which we will rename to "components" later on insteadApp.svelte: Delete everything but the tags
App.css: Delete place-items:center ( line 30 ) since it'll make everything become center and we don't want that
lib : Rename to components
Delete Counter.svelte
About, Experiences, Projects are link to our sections, Thursday is the current date ( we'll use JavaScript Date Object to make this )
components folder, create a file called NavBar.svelte and add the necessary tags as followNote: You don't need to have all tags as below, you can even have just a
<nav> </nav>tag and it's still valid in Svelte
<nav> </nav> ( because if you want to display something, it has to be within a HTML tag ) in your NavBar.svelte file and save it
<p> </p>tag stands for paragraph
npm run dev, it won't display that words because you have to import it in App.svelte - our main Svelte fileNavBar.svelte and start creating our navigation barYou can copy paste this code block and read the comments to understand more
<script>
</script>
<nav>
<!-- We're creating a navigation bar with 3 items: About, Experiences, Projects\-->
<section class="container__nav" id="/">
<ol>
<!-- the href=#something links to each section so we can create a scroll to section feature\-->
<li>
<a href='#About' class="nav__item">
About
</a>
</li>
<li>
<a href='#Experiences' class="nav__item">
Experiences
</a>
</li>
<li>
<a href='#Projects' class="nav__item">
Projects
</a>
</li>
</ol>
</section>
</nav>
<style>
/* This is CSS style for our navigation bar */
ol {
list-style: none;
}
li {
padding: 0;
}
.container__nav {
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.nav__item {
color: white;
font-weight: 600;
font-size: 2rem;
margin: 0 2rem;
transition: all 400ms;
}
.nav__item:hover {
color: rgb(0, 157, 255);
}
.time {
color: #1a1a1a;
font-weight: 700;
background-color: #2C91C6;;
padding: 0.35rem;
margin: 0 2rem;
border-radius: 12px;
}
</style><ol class="container__nav" id="/">
<!-- the href=#something links to each section so we can create a scroll to section feature-->
<li>
<a href='#About' class="nav__item">
About
</a>
</li>
<li>
<a href='#Experiences' class="nav__item">
Experiences
</a>
</li>
<li>
<a href='#Projects' class="nav__item"\>
Projects
</a>
</li>
</ol>NavBar.svelte
<script>
// @ts-nocheck
history.scrollRestoration = "manual" // Prevent automatic scrolling
const navItems = [
{ title: "About", url: "#About" },
{ title: "Experiences", url: "#Experiences" },
{ title: "Projects", url: "#Projects" },
];
</script>
<nav>
<section class="container__nav" id="/">
<ol class="container_nav" id="/">
{#each navItems as { title, url }}
<li>
<a href={url} class="nav__item">
{title}
</a>
</li>
{/each}
</ol>
</section>
</nav>
<style>
ol {
list-style: none;
}
li {
padding: 0;
}
.container__nav {
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.nav__item {
color: white;
font-weight: 600;
font-size: 2rem;
margin: 0 2rem;
transition: all 400ms;
}
.nav__item:hover {
color: rgb(0, 157, 255);
}
.time {
color: #1a1a1a;
font-weight: 700;
background-color: #2C91C6;;
padding: 0.35rem;
margin: 0 2rem;
border-radius: 12px;
}
</style>Display the current date with custom parameters
We can do that in the <script> </script> that allows us to use JavaScript magic
let time = new Date(Date.now()); // Create Date Object
const options = { // We'll need this option for toLocaleDateString() method later on to display on the weekday
weekday: "long",
};Then we can display it in our html like this to display current weekday:
<p class="time">{time.toLocaleDateString(undefined, options)}<p>NavBar.svelte<script>
// @ts-nocheck
history.scrollRestoration = "manual" // Prevent automatic scrolling
const navItems = [
{ title: "About", url: "#About" },
{ title: "Experiences", url: "#Experiences" },
{ title: "Projects", url: "#Projects" },
];
let time = new Date(Date.now());
const options = {
weekday: "long",
};
</script>
<nav>
<section class="container__nav" id="/">
<ol class="container__nav" id="/">
{#each navItems as { title, url }}
<li>
<a href={url} class="nav__item">
{title}
</a>
</li>
{/each}
<p class="time">{time.toLocaleDateString(undefined, options)}</p>
</ol>
</section>
</nav>
<style>
ol {
list-style: none;
}
li {
padding: 0;
}
.container__nav {
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.nav__item {
color: white;
font-weight: 600;
font-size: 2rem;
margin: 0 2rem;
transition: all 400ms;
}
.nav__item:hover {
color: rgb(0, 157, 255);
}
.time {
color: #1a1a1a;
font-weight: 700;
background-color: #2C91C6;;
padding: 0.35rem;
margin: 0 2rem;
border-radius: 12px;
}
</style>Originally posted by @anhduy1202 in anhduy1202/DevBlog-yt#3