Svelte Tutorial for Beginners #19 - Header & Footer Components

Net Ninja · Beginner ·🌐 Frontend Engineering ·6y ago

Key Takeaways

Creates a header and footer component using Svelte

Full Transcript

okay let my friends so in this video I just want to focus on fleshing out the header component and also the footer components at the top and the bottom of the website essentially but first of all I'd like to also do a little bit inside the root component just a tiny little bit so first of all I'm gonna do a paragraph tag and then just type out some lorem here and that's just so we have something to play with on the screen so let me save that and preview over here and we see this paragraph going all the way from the left to the right now instead of the content spanning all the way across I'd like to create a column of content which sits in the middle which has a maximum width of about 960 pixels and then the margin is auto left and right so we have space on the left and on the right so to do that I'm going to target the main tag or right here and I'm going to say that the max width will be 960 pixels and I'm also going to say that the margin can I spell this margin is going to be about 40 pixels top and bottom also left and right if I save this now you'll notice that the maximum width is this right here it still looks quite wide but that's because I'm zoomed in if i zoom out a little bit see it 100% we can see now we have this central column right here and we have a margin on the left and the right so that's all I wanted to do really inside this Aptos felt component now then what I'm going to do is create a new folder and I'm going to call this components I'm just going to stretch my code a little more than we did in the previous tutorials so this folder right here is going to be for our components like the footer the header the pull form the pull list etc now you can structure your code differently that's absolutely fine this is just so we can stay organized for now and generally in bigger projects I would have different folders for each feature or section of the website but in our case that's a bit over the top so this will do for now so now let's create a header component we'll call this header dos belt and inside here first of all I'm going to do a script and then at the bottom we'll have some of styles so style tag as well and then let's flush out the template first of all so the head of its is just gonna be a header tag like so and inside the header we're gonna have an h1 and inside the h1 not some text but instead an image and in fact you know what we don't even need a script because there's going to be no kind of logic or data inside this component so let's get rid of all of that and just have the HTML template and some Styles now the alt attribute is going to say Paul ninja logo and we now need to add this image right here so we're gonna add that inside the public directory and it's gonna go inside a folder so new folder called image so I already have this image prepped it's an SVG and you can find this on the guild repo for this lesson I'll leave the link down below so this is the SVG preview but you're gonna see what it looks like on the screen when we add it in right here so we want to go inside the image folder and then forward slash Paul underscore ninja under school logo dots SVG so if I save that and prove your then if we refresh okay we can't see that that's because stupidly I've not actually imported the header components into the app component right here so let's do that now so imports header from and it's docked forward slash going to the components folder and then header dots felts and now we need to choose where to put this on the page it's gonna go above the main tank right here so let's do that header like so save it and now we should see that over here on the screen okay so that's the logo however looking pretty stupid and rather big so let's now add some styles to the header so first of all I'm going to target the header tag itself the background of this is gonna be a really light gray so that's going to be f7 f7 f7 and it's more kind of an off-white now I also want to apply some padding to this of 20 pixels all the way around now let's move on to the h1 and the h1 is going to have a merchant of 0 so we're just stripping out the default margin of the h1 in the browser and then we're going to say text align is going to be Center that so the image is centrally aligned let's have a look so far okay so looking a bit better but now we need to reduce the size of this image so I'm going to come down here and say image and the max width of this image is going to be about 180 pixels okay so save that and that is looking a lot better so I'm just going to inspect this at the minute because I can see some kind of border or margin around the body it's the padding so I think that's in the global stylesheet I'm going to actually remove that so let me go to the global style sheet which is here Global CSS and you can see we have some padding right here let's get rid of that we don't want that save it and that looks a bit better so it now sits flush to the top left and right okay so the next thing I'd like to do is a footer component just to add a copyright notice or something down at the bottom so let's create that we'll get rid of the header for now create a new component inside the components folder called footer dot svelte and inside here we don't need a script again let's just do a footer tag for the template and then a div with a class of copyright and inside here we're just gonna say copyright 2020 Paul ninja all right sir now let's do some styles and before we do any styles let's just take this component and place it inside our app file so I'm going to duplicate this line and change this and this to footer instead and we're going to output the footer underneath the main tag so footer like so save it and preview and we should see this copyright notice right here now I want to centrally aligned that so let's go to the styles and I'm gonna say footer first of all I mean side that will give this some padding of around 40 pixels I'm also going to say text align is going to be Center now I want to style this as well copyrights but before we do that let me just spell this correctly so down here I'm going to say copyright and then inside the color this is going to be kind of like a light gray instead of black just to make it a bit more subtle so AAA and then the font size there's going to be 14 pixels their display is going to be inline - block and the padding is going to be 20 pixels all the way around and then finally a border top of one pixel solid and a lightish gray color DDD so if I save that now and prove here over here this looks a bit better now when we have more contents in the center it's gonna look better because this will be at the bottom of the page but for now that's looking pretty good but we have this padding back at the top I don't know why that is oh it's because we're loading old styles just hard refresh over here to get rid of that padding if it's showing up on yours okay then so that is the basic template done now we have the header components and we also have the footer component and we've styled the content in the middle a little bit as well now we don't need that so we can get rid of the paragraph content right here that was just so it could style it properly now in the next video we're going to create some tabs for the top over here so we can switch between two different views we have one section for showing the polls and one section for adding a new poll or form so we're going to create some tabs in the next video to switch between two different components showing on the screen

Original Description

🐱‍👤🐱‍👤 JOIN THE GANG - https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg/join ---------------------------------------- 🐱‍💻 🐱‍💻 My Udemy Courses: + Modern JavaScript - https://www.thenetninja.co.uk/udemy/modern-javascript + Vue JS & Firebase - http://www.thenetninja.co.uk/udemy/vue-and-firebase + D3.js & Firebase - https://www.thenetninja.co.uk/udemy/d3-and-firebase 🐱‍💻 🐱‍💻 Course Files: https://github.com/iamshaunjp/svelte-tutorial/tree/lesson-2 🐱‍💻 🐱‍💻 Other Related Free Courses: + HTML & CSS Crash Course - https://www.youtube.com/playlist?list=PL4cUxeGkcC9ivBf_eKCPIAYXWzLlPAm6G + Modern JavaScript - https://www.youtube.com/playlist?list=PL4cUxeGkcC9haFPT7J25Q9GRB_ZkFrQAc 🐱‍💻 🐱‍💻 Svelte Docs https://svelte.dev/tutorial/basics 🐱‍💻 🐱‍💻 The Net Ninja Community Boards: https://community.thenetninja.co.uk/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 0 of 60

← Previous Next →
1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

Related Reads

📰
Inside the Wayfair Frontend SDE-2 Interview: A Complete Breakdown
Learn how to prepare for a Frontend SDE-2 interview at Wayfair, including online assessments, machine coding, and system design.
Medium · Programming
📰
I Spent Two Years Maintaining a React SPA. HTMX Rebuilt It in a Week
Learn how HTMX rebuilt a React SPA in a week, replacing 2 years of maintenance work, and discover the benefits of this alternative approach
Medium · Programming
📰
The 5 Levels of Front End Engineering (And Where Most Developers Get Stuck)
Learn the 5 levels of front end engineering to improve your skills and avoid getting stuck in a career rut
Medium · Programming
📰
Browser-Based PDF Editing with Vue 3 and pdf-lib
Learn to build a browser-based PDF editor using Vue 3 and pdf-lib, enabling users to edit PDFs directly in the browser
Dev.to · sunshey
Up next
Coding YouTube-like app: Part 5
Stephen Blum
Watch →