Placeholder Image

字幕表 動画を再生する

  • Hey, thanks for checking out this video.

  • We're going to cover the basics of Sass, and then we'll create a project from scratch and deploy it, and I'll show you how you can easily include sass in your workflow.

  • And I want to give a big thanks to Bo and free code camp dot org's for publishing this video free code camp is an awesome resource.

  • And on behalf of the community, thank you for all that you do.

  • So before we get into this video, I'd like to quickly let you know who I am.

  • I'm a husband, a father and a programmer.

  • I've got over two decades of I t experience.

  • I'm a full stack developer.

  • I recently decided to create a YouTube channel, and initially I just wanted to help people.

  • But after my first couple of videos, I realized that it's actually helping me to become a better programmer.

  • I do research for every video, and a lot of times I come across things that I didn't know or a better way of doing things.

  • So I'm learning and teaching at the same time.

  • So when win, my channel is new, but I upload new videos every week had greatly appreciate it.

  • If you check out my channel and subscribe and that's enough of this, let's get into the video.

  • So we're gonna go over the basics of sass and set up our environment, and then we'll go through a project from beginning to end using SAS.

  • There's time stamps in the description if you'd like to skip through certain parts.

  • So what is SAS?

  • It's a CSS extension language and gives your CSS superpowers.

  • Once you see how easy it is to write and how logical and organized it can be, you'll never write Plane CSS again.

  • You'll see what I mean.

  • In a minute.

  • Let's look at what you need to write CSS.

  • First, you'll need a code editor, and I recommend V s code because it's open source and has great extensions and awesome community support.

  • Now your browser can't read SAS, so it has to be compiled into plain CSS.

  • But don't let that scare you.

  • It's easy.

  • There's several ways that we could go about this.

  • We could use no j s to run a compiler that will watch our SAS files and compiled them automatically for us.

  • But we could use Gope to do the same thing or we could use an extension in V s code.

  • And for this video, that's what we're going to do.

  • We're going to use live SAS compiler.

  • Another extension that we're going to use is live server.

  • If you're unfamiliar with V s code and how to set it up for Web development, I do have a video on that.

  • I'll have a link in the description below.

  • All right, I'm gonna quickly walk you through installing the live SAS extension so N V s code will go to extensions and we will search for live sass.

  • And there you'll see live SAS compiler.

  • Go ahead and click on that and then click install.

  • And after that's installed, we're going to look at some settings.

  • So let's go to our settings, and then we'll search for sass and then click on Life's Ass compiler there and then you'll see in the format settings.

  • We're gonna want to change the save location.

  • Now these settings are a personal preference.

  • By default, it will compile your CSS and put it into the same directory.

  • And I prefer for the compiled file to go into my distribution folder.

  • It's a little click on edit in settings, Jason.

  • And then here we're going to add some settings.

  • So these are your options.

  • So the default is at the top here, format is expanded, so there's no compression going on.

  • The extension name is dot CSS and then the safe path is no.

  • So that means it's going to go into the same directory as your SAS files.

  • So you could also change the formats who compressed if you want, and it will go ahead and compress.

  • And men, if I your CSS all in one shot and then you could change the extension name to dot men dot CSS and then you see what they're where we can put it into our distribution folder.

  • So I'm actually gonna do just a combination of the two for this video.

  • We're gonna keep the format at expanded and the extension as Nazi SS, and we're just gonna change the safe path.

  • Thio slash dest slash CSS and then we'll save that and we're good to go.

  • All right, now that we have all of that set up, let's create a standard folder structure here.

  • So I have a new project folder that I've created and opened it in V s code.

  • And let's go and create a folder here called Dist.

  • And then within our dissed folder will create in html file index dot html.

  • We'll use Emmett Will use exclamation enter, get a template here.

  • And we'll just name this says tutorial that will add a link here to our CSS.

  • So currently, we don't have one, but we will be adding it noticed the extension here is CSS not sass or S C.

  • S s.

  • So this CSS file is what's going to be compiled eventually once we've created our SAS files.

  • Now, before we create our SAS files, it's important to understand that there are two syntax is supported by SAS.

  • So there's the S C.

  • S s syntax and it uses the file extension s C S s.

  • And this stands for sassy.

  • CSS is basically a super set of CSS, which means essentially that all valid CSS is valid.

  • SCS ESAs Well, I'll show you that in a minute.

  • But because of this similarity, it's the easiest syntax to get used to and the most popular and the other syntax is the indented syntax And this was the original sin tax Versace.

  • And it uses the file extension.

  • That s a s s.

  • The indented syntax supports all of the same features as S CSS, but it uses indentation instead of curly braces and semi colons.

  • There are a few other minor differences, but we're not going to be using S a s s in this video, so we're not gonna go over those, All right, so we'll be using the S C.

  • S s syntax.

  • And so let's go ahead and create that structure.

  • So be sure you're in the root of your project.

  • And Gwen, create another folder here.

  • We're gonna name this S C s s.

  • And then within here, we're going to create a main dot F C.

  • S s right.

  • Now that we have that file open, we've got our extension installed.

  • So now you should see this.

  • Watch SAS at the bottom.

  • So go ahead and click on that and you're going to see an output here.

  • We'll see here that it's watching for our SAS files now, and it is compiling and generating them automatically.

  • And now it's watching for us to save the file again.

  • And when we save it, it's gonna automatically re compile and create that CSS file every single time that we saved the document.

  • And so we didn't add this CSS folder here, but now we have a folder in dist.

  • And so that extension created the folder and created our CSS file.

  • And of course, we don't have anything in our SAS file and so I don't expect to have anything in our CSS file either.

  • So remember we said that any valid CSS is also valid sas So let me show you what I mean by that store here in our SAS file, we can ad let's just do something generic here will say body fat ground and we'll set it to blue and I'll hit save and it automatically compiled or CSS for us.

  • So now if we go to the CSS file, we'll see body background blue just the same as we see it here So we can write plane CSS in our SAS file and it will work just fine.

  • So I also have a live server installed, so I'm gonna go ahead and hit that Go live and here you see, we have a blue website So an important note here is that we should never modify the CSS file on Lee modify the S CSS file every time the compiler runs is going to overwrite the CSS file.

  • So the first SAS feature that we're going to look at is variables.

  • Now, you might say CSS has variables to, and that's true.

  • CSS does have variables now, but SAS has had variables long before CSS.

  • Currently CSS variables compatibility across browsers is about 90%.

  • So that's pretty good.

  • And I don't see any reason not to use the SS variables.

  • But when you use SAS variables, they don't compile into CSS variables they compiled to the actual value.

  • So let me show you what I mean.

  • There.

  • So in normal CSS we could add variables like this.

  • So now we could set our background here using a CSS variable just like that.

  • So now if I save this, you see that our CSS file is pretty much identical to the S CSS file and if we switch over to our website, we now have a great background.

  • So now let me show you the difference between this and the SAS variables.

  • So with sass we can get rid of the route and instead of the dashes will add a dollar sign.

  • So the dollar sign indicates that it is a variable.

  • So instead of calling bar, we will just input the variable.

  • And I'll say this will switch over to our website and it's still great.

  • And let's look at our CSS now.

  • We don't have any variables defined.

  • It puts the actual value there.

  • So using SAS variables has 100% compatibility across browsers.

  • All right, next, let's talk about maps, So if you're familiar with JavaScript, you could compare maps to a raise.

  • Maps are lists of key value pairs, so I'll create one here so we'll define a variable and we'll name it Font waits and then tow to define a map.

  • We start with parentheses, so answer a key.

  • So we'll say regular will be the key, and then the value will be 400 will enter another one.

  • We separate these by commas, so we'll say medium.

  • We'll be 500 then bold will be 700.

  • And it's probably not the best example, but you can create a map of colors or different things, so that we have something to really add.

  • This, too.

  • Let's put some HTML mark up in here so we'll add a Div with class of Maine and then we will put a paragraph and we'll just put some warm in here.

  • 50.

  • All right, it's now on the body.

  • We could apply, uh, fart.

  • Wait globally.

  • If we wanted to get a value out of the map, will use map, get it right and so is looking for the map.

  • And that would be fun waits.

  • And then the key would be, let's say, gold.

  • So this may seem like a bit much, but if we have our font waits defined throughout our CSS in many different areas and for some reason we want to change the way that the normal medium or bold font looks, let's say we want bold to actually be 900 instead of 700.

  • I could change in this one spot instead of searching through all of my CSS and changing it on each individual line.

  • Now, before I save this, let me pull up the website now and our text.

  • We forgot a text color.

  • Let's apply our color and we'll set that to text color.

  • But now we see that everything is in bold.

  • So this looks at our map and we tell it which key to look for.

  • It finds the key and then it extracts the value and it puts the value here a spot.

  • Wait, we go to see SS will see that our font wait to set the 700.

  • All right.

  • Next let's talk about nesting.

  • So nesting might be one of the best features of sass.

  • But depending on how big your project is, be careful with too much nesting.

  • Using classes that can be reused instead of nest after nest is much better.

  • But to demonstrate nesting, we will look at our paragraph here, so we have ah Dee of the class of Maine in a paragraph.

  • So let's look at the main Dev.

  • First, let's say that we want to center it and handsome margin on the side.

  • So also set the with here, too.

  • 80% and we'll set margin top and bottom to zero left and right to auto and this is just plain CSS.

  • So if we go here, we'll see.

  • Now it's centered and we've got some margin on sides.

  • All right.

  • So now if we wanted to style or paragraph, normally we would have to do main and then paragraph and do it like this, or we could just do paragraph, and that would globally change all of the paragraphs.

  • But we don't want to do that with sass.

  • We can nest.

  • So within Maine, we could just do this.

  • And let's say we just want to put that fun.

  • Wait on, Leon, This paragraph.

  • We'll move it down here and I'll save that switch and we'll see Same thing.

  • Nothing has changed.

  • If we go to our CSS, you'll see that it has written it as proper CSS so that the browser can parse it.

  • Now, if you want to do this properly, um, let's add a class here to the paragraph.

  • We'll set it to Mein Herr Graff.

  • And then So instead of targeting the tag directly, we could do main here a graph.

  • I say that now it compiles properly into CSS.

  • But with sass, we have some shortcuts.

  • So instead of typing main again, we could take this part out and we can use an AM present.

  • So am Priz n equals the parents.

  • All right, so we save that and go to our CSS.

  • Now it's not quite right, cause its main underscore paragraph on its own, not within the main parent.

  • So to fix that, we actually have to use something called interpolation.

  • What that means is we don't want just dot main paragraph.

  • We want everything before it s so we have toe wrap the AM present in hashtag curly braces.

  • So now what we could do is at a hover on the paragraph and so we won't add that on the paragraph, not main.

  • So it will nest that again.

  • And this time we'll use just one AM present and we'll use coal and hover like we would normally.

  • And then let's just change the color to feel all right now save this.

  • And if we go to our website and we hover over it now it's pink.

  • All right, let's look at our CSS.

  • Let's see what happened here.

  • So we've got everything separated as it should be in CSS now.

  • So let's talk about separating files.

  • So with sass, we can create partial SAS files that contain little snippets of CSS that you could include in other SAS files.

  • So if we're working on a large project, it's a great way to module arise your CSS and make things easier to maintain.

  • A partial is simply a sass file named with a leading underscore.

  • So the underscore Let's SAS know that the file is only a partial and that it should not generate a CSS file.

  • So the compilers going to ignore those files that begin with an underscore.

  • So let's create a partial here.

  • Make sure that you're in your S C.

  • S s folder and we'll create a new file and we're going to name it.

  • Underscore resets.

  • That s C s s all right.

  • Now in this resets file, we're just going to include our normal resets.

  • So we will do a box sizing of border box, margin zero and padding of zero.

  • All right.

  • Just some normal resets there.

  • I'm going to say that and then in our main S CSS want to include them at the top here because generally will have our resets at the top.

  • And so to include that we will use and at import, and then we will indicate the name.

  • So notice here that we don't have to put the underscore or the extension.

  • So now if I save this and we look at our main CSS, it has compiled our resets into our main CSS from the partial and also noticed that the vendor priest fixes are automatically added by the compiler.

  • So what we could also do is we could create another file here, and we could name it underscore variables, that s C.

  • S S.

  • And then in our variables, we could take all of these and we'll put them into our variables partial.

  • And I'll say that and then gonna use all shift down arrow to duplicate that and will include are variables.

  • So now if I say that, you'll see that the variables are still working.

  • So by using partials, we could separate major components into partials.

  • And this is especially helpful when working with a team on large projects.

  • We can break up the components and work on them individually.

  • All right, so now let's talk about functions.

  • So if you're familiar with javascript, functions and SAS are very similar.

  • So to create a function, we'll put it here at the top, and I'm gonna say at function to define that this is a function, and then we will name it so this Ah, this map get in the font waist down here.

  • It's a bit much.

  • It's kind of ugly.

  • We can shorten that up, especially if we're gonna be using it all over our CSS.

  • So we're gonna create a function that is called Waits, and then we're going to open parentheses and we're going to put an argument in here.

  • We're going to put a variable of wait name and then we're gonna open it with curly braces within the function.

  • We're going to return, and we're going to use map gets and we're going to target the font waits, and the key is going to be our waits name.

  • So this variable here is one of you passed within our SAS file whenever we call it.

  • So instead of map, get down here, we're going to use the function name Wait.

  • And within that will pass it the weight name that we're looking for.

  • If we change this to regular, it would return the regular Wait.

  • So let me say this.

  • We'll go to R.

  • C S s.

  • Now we're looking for the font.

  • Wait, let's see.

  • What what it is want wait of 400 right?

  • So that's our regular funds.

  • If I go back here and change it back too bold and we check our compiled CSS now it's 700.

  • Right now we'll move on to mix ins, and so mix ins are similar to functions.

  • So to demonstrate this, let's add some more HTML markup.

  • So I'm gonna just duplicate this, uh, this paragraph here when youse all shift down arrow create another paragraph and I'm going to say that then back in our SAS file in the main here, let's say we want to display.

  • This is flex and we want to justify the content center and a line items center.

  • If you haven't learned CSS Flex box and CSS Grid.

  • I have videos on those as well.

  • I'll put links in the description below.

  • Let me save this and let's switch over to our website and we see now that our paragraphs are side by side because we define them.

  • Ask Flex by the thought that was gonna flex to a row, Go back to our code here and let's just say that we have many of these flecks boxes that we need to create, and we don't want to type, display, flex and justify content in the line items a 1,000,000 times.

  • So we'll go up here and we're going to create a mix in so at symbol Nixon and we're going to name this and we'll name it Flex Center and then within Flex Center.

  • We're going to put all of this content that we don't want to repeatedly type.

  • And now with in Maine, instead of typing all of that, we will include the mixing, so at include and then flex center just like that.

  • Now I'll say that and let's check out our CSS and in our main we've got all of our flex.

  • And again it's added all of the vendor prefixes as well.

  • Now similar to functions, we could also pass an argument into the mix in.

  • So let's say we want to pass it direction and then we could define flex direction as direction.

  • So now, instead of including Flex Center, we're going to also include an argument here and by default it is a row.

  • So let's, uh, let's define it as column, and I'm going to say that and let's go back to our website and now you'll see that they are in a column and not a rope.

  • And of course, if I change this to row and save it and now you'll see they're in a row are so mix ins and functions are very similar.

  • But just remember that functions should be used to compute values and return values.

  • Mix ins should define styles.

  • Another example of a mixing is choosing between a light and dark theme.

  • So by default, right now, our website is a dark theme, so we could add a mix in.

  • We'll name a theme and we're going to pass it a Boolean value so we can assign Boolean values two variables.

  • So we will say light theme and by default, we're going to set it true.

  • So now again, if you're familiar with Java script, we can incest.

  • We can use if statements.

  • So we're gonna say if light theme, that means if light theme is true, then we're going to set background.

  • Currently, background is set to primary color.

  • But what we're gonna do is we're gonna wrap this in a lighten, and we could tell it how much delight in it by we're gonna say 100% so it's basically going to invert the color, and then we will need to set the color as well.

  • Apparently, that's set to the text color.

  • The text color is white by default, so we're going to need to do the opposite.

  • So we're going to dark in the text color, and we're gonna do that by 100%.

  • All right, so now to use this, we're going to create a Let's go down here at the bottom and we're going to create a light class and we're going to include our theme.

  • We're going to pass it that variable so light theme.

  • True, I don't have to actually typed this light theme.

  • I could just say true, this makes it a little bit more identifiable.

  • All right, so let's save this.

  • And now we need to add this class somewhere.

  • So let's just, uh, let's just add it to the body for now.

  • Class of light.

  • See that?

  • And now let's go to our website.

  • Now we have a light theme.

  • So now if we change this to false, let's see what happens.

  • It's still a dark thing, even though we have the class of light on body.

  • It's still a dark theme.

  • How is that possible?

  • So let's look at our main CSS.

  • We've got our body here remain over Amane paragraphs.

  • But there's no light theme here.

  • Go back to R.

  • S, C.

  • S s and we've got it included here.

  • Well, we've included theme and we've said false.

  • So if we go up here to theme so if it's true, it's going to add these CSS styles to the light class.

  • If it's false, it's not going to add anything.

  • So that means the light class is empty.

  • So when the compiler runs, if it finds a definition that's empty, it's just not going to include it in the CSS at all.

  • All right, So if I go back here and I change this back to true, let's look at the compiled CSS.

  • And now we have our light class right back in our main SAS file.

  • Mix ins are pretty cool, so I'm gonna show you one more mix in This one has to do with Media Query.

  • So we're gonna create a mix in, and we're gonna call it mobile, and then we're going to use a media query so just a normal CSS media query we're gonna say Max Witt of let's just say 800 pixels and then in here we want to include content, so this content will be passed when the mixing is called.

  • Now, what we also could do instead of defining this, um, this with here, we could actually use a variable.

  • And it would be better to use a variable, because if we ever want to change, it would be easy to change.

  • So we're gonna create a variable here called Mobile.

  • And we will just set that to 800 pixels and then back here in our SAS file instead of putting the value, their 800 pixels will just include the mobile variable.

  • All right, so now let's see.

  • What did I miss here?

  • Content.

  • There we go now to include this.

  • Let's say if the with gets below 800 pixels, we're gonna want that to change to a column.

  • All right, so here, within main.

  • So here we're going to include our mix in, some include, and then that is going to be mobile.

  • And then within this basically view this as your media query.

  • So what do you want it to do when it's below 800 pixels.

  • So we're going to say flex direction calling.

  • All right, let me say that and I'll switch to the website.

  • All right, so let's make this smaller, And there you go.

  • Once we get below 800 pixels, it changes to a column, right and then move it back over.

  • It's back to a rope, all right.

  • And then if we ever need to change the wits, we have the variables here where we can change our wits.

  • All right, so now let's talk about extensions so we can extend an element.

  • And so the element that we extend it to would then inherit all of the styles from the selected element.

  • So to demonstrate that let's go to our HTML, we'll change the classes to paragraph one and paragraph two.

  • All right, so now here we will change this to paragraph one.

  • And so let's say that we want to extend all of the styles of paragraph one on two Paragraph two.

  • We want them to look the same, but we just want to change one or two things on paragraph two, and we don't wanna have to re type all of the styles on both paragraphs so we could do this.

  • We have to interpret it again the AM present, and then we'll do a paragraph two.

  • And then here we could extend main Hera.

  • Graf won.

  • We'll save that switch.

  • And now they're both identical, just as they were before.

  • But now we want to make a change to this paragraph.

  • So I've extended all of the same properties.

  • But let's say we want to We'll use hover again, and this time we'll change the color to our accent color.

  • All right.

  • And so now we have our accent color.

  • So if there was a bunch of styles here in paragraph one and we didn't want to re type everything, we could just extend from that class onto this class last thing that we're going to look at its operations, So addition, subtraction, multiplication division.

  • So a normal CSS we could do, uh, help, and then I don't know why I would want to do this, but if for some reason we wanted to subtract 40% that would work just fine.

  • But incest?

  • We don't need the calculation and it will work just like this.

  • We'll hit, save, Go back and just the same.

  • Now, one thing to note, with the normal CSS calculation, I could do minus 400 pixels and see.

  • This will work just fine.

  • But with cess, we can't mix types, so the operation has to be of the same type.

  • So for using percentage, they all have to be percentage or they'll have to be pixels.

  • So now let's see what that looks like in the CSS.

  • We have 80% minus 40%.

  • So now we just have the result of that, which is 40%.

  • So if we so for use the normal CSS count, let's look at what the compiled CSS looks like.

  • It was gonna go and pass that entire calculation into our normal compiled CSS.

  • All right, so that's pretty much the basics of sass.

  • So if you want to learn more, you can look at the documentation on SAS Dash lang dot com.

  • Sass is very powerful, and once you get the hang of it, it's hard to go back to normal.

  • CSS.

  • All right, now let's look at a real world example.

  • So this is what we're going to build.

  • A portfolio website has this cool animated menu and several pages and the menu along with the entire website is responsive.

  • We're going to take a mobile first approach when we build this.

  • So here I've got V s Code open and I've created a project folder on my computer.

  • And then I opened it and GS code and all that I've done so far is I created a dest folder along with an image folder, and I just brought in the images that will be using in this project.

  • I will have a link in the description below so that you can download the project files as well.

  • So in the dist folder, let's start out.

  • By creating an index that html file.

  • I'm gonna close the sidebar by pressing Control B.

  • And now let's start with our HTML markup.

  • So we use emit exclamation enter That gives us a boilerplate.

  • And let's title this.

  • We'll just go with Mike Smith Portfolio.

  • We're also going to add our style sheet, which will be created for us for more sass.

  • So add a link and we'll set that to CSS main dot CSS in the body here, we're gonna start out with a header And then we will create a div with the class of menu button and then within here will create a span with the class of menu button burger.

  • So the menu button is going to be pure CSS.

  • We're not going to use any images or fonts for that.

  • Within the header, let's create a knave will have a class on that of Neve.

  • Then we'll create our menu items so we'll have a UL with the class of men you nev.

  • And then our allies will have a class of men.

  • You knave item.

  • Right now we'll have a link with the class of men, you knave link.

  • Okay?

  • And that is going to go.

  • So our 1st 1 will be home.

  • So that's index dot html and we'll name that one home.

  • All right, so now we're going to take this ally, and we're gonna duplicate it down three times.

  • So all shift down, Arrow.

  • 123 So, in our home, this is the page that we're on right now.

  • So we're gonna set this ally too active, and then the next one will be our about.

  • So we'll say about me on the next one.

  • Is our projects.

  • I will say my projects.

  • And the last one is our contact, and I will say Contact me.

  • All right.

  • I think that's it for the header.

  • Let's go to our main section now.

  • All right, we're gonna start with a main tag, and then we'll have a section and we have a class of home, and then we'll create an H two on in here will say I Oh, my name is than each one with the class of home name.

  • Then here will put the name so, Mike, and then we're gonna have a span.

  • The class of home name last in here with the last name, uh, Smith.

  • And then we'll have an H two.

  • And this will be his titles Web developer, designer and prove grammar.

  • Right now, we're gonna add our social icons were actually gonna put that in our section.

  • Still, So we'll add a div with the class of social icons and then a link and that z not gonna go anywhere.

  • And then we'll add the icons were gonna use, um, Renee's font.

  • Awesome.

  • And I'll show you how to set that up in just a minute.

  • So we're gonna use an icon with the class of F A B and another class of F A Twitter.

  • And we're also gonna add a class of F A times two.

  • All right, And then let's take these three lines and copy that down.

  • Three more times they will change.

  • Twitter, too.

  • Facebook, then Instagram and get up.

  • All right.

  • And then after that one last thing is Ah, footer!

  • And that's just going to contain our copyright soul Do and present copy for the cooperate symbol.

  • And then copy, Right?

  • Whatever you current year is, we're going to have some basic Java script.

  • We're going to include a script, the source and the source will be j s main dot Js.

  • All right.

  • I think that is it for the markup.

  • So let's look at the fun.

  • Awesome.

  • We also have to add something here for that.

  • All right, so this is fun.

  • Awesome website, and they recently changed things up a little bit.

  • You actually have to sign up for a free account.

  • So I've already logged in, and I'm just gonna go to my kits.

  • And here's kit that I have is what we need to do is to copy this script and put that into our HTML files.

  • So I'm just gonna hit copy code, and then we will put that here.

  • All right, So I think that is it for the index dot html Let's go ahead and save this and we'll see what this looks like.

  • So I have have live server installed.

  • So if you just right click here, you can say open with life server or you can see there's some shortcut here.

  • You can see that That looks pretty ugly.

  • There's no C s s.

  • So Okay, so let's start with our sass.

  • I'm gonna open the sidebar by pressing control B and then make sure that you're in the root and create a folder s C s s then within s CSS.

  • We're going to create ah file of Mein Gott s C.

  • S s.

  • And we're actually going to start with us, created another file and we'll name it Underscore config.

  • That s C s s.

  • So that's gonna be a partial and we're actually going to create partials for all of our elements in a large project.

  • That's what you would do.

  • You would separate everything into partials.

  • This isn't a large project, but we're gonna go through that workflow so that you can see it when they close The sidebar here, control be in our config.

  • We're going to have our variables, so we'll have a primary color and that's going to be a dark gray.

  • And then we'll have our secondary color.

  • And that will be, uh, and orange, and we'll put our resets in here.

  • So box sizing border box large in zero, adding zero just some standard resets.

  • All right, I'm going to say that, and then we'll go to our main CSS, and the first thing we need to do is import that config.

  • So say, Import Fig, we don't have to put the underscore or the extension.

  • All right.

  • First, let's look at the body, and we're gonna set the background to the primary color, and then we'll set the text color for now.

  • We'll just set that to White.

  • We're gonna come back to that in a minute.

  • On the height would be 100 VH.

  • So 100 view height view view that as a percentage.

  • So basically it's 100% of the available view.

  • Port height, change the font family like the's you and we're gonna set the line height.

  • So one All right now was we're gonna target are H one H two and H three And I want the funt weight of those to be a little bit less more normal.

  • 400.

  • Then we've got some links in here, so I'm gonna target all of links globally.

  • And we're going to set the color Thio White for now and the text decoration to none.

  • All right, And then let's look at header.

  • So for the header, we want it to have a position of fixed.

  • We need it to always be on top of everything else.

  • So we're gonna set a Z index of two ah, with of 100% and padding of one room.

  • So if you're unfamiliar with ah rim and M units, so realm units are based on the font size of the body.

  • So the default font size of the body is 16 pixels and so 11 rim would be one times 16 to rim would be too time 16.

  • So that would be 32 pixels.

  • If we change the font size of the body to 20 pixels than one room would be 20 pixels into room would be 40 pixels.

  • M e m.

  • It's pretty much the same thing, except it's not based on the font size of the body.

  • It's based on the font size of the parent.

  • All right, so now let's go to our C main target the main here, and we'll set the heights of 100% and a width of 100%.

  • And then we'll start doing some nesting.

  • Was target our social icons for that.

  • For those, I want them to be positioned fixed with a bottom.

  • So from the bottom one rim and from the left, one room within the icons there are links.

  • So its target those we want a padding on those of, say, 0.4 rim.

  • And then on hover, we're going thio, change the color.

  • We'll set that to our secondary color.

  • Lastly will target our footer and we will set the font size on there to one rim.

  • We're gonna set a fixed position on this as well, because we're gonna We want that to be at the bottom.

  • Say bottom 0.4 room.

  • Then write one room, do a text the line right padding of one room, and we'll set the color on that too white for now.

  • So before we save this unloaded, we actually have to initialize are SAS extension.

  • So we're running the life's ass compiler extension.

  • So what we'll do is we'll hit watch sas if you don't have V s coat set up.

  • I've got a video with the web death set up where we walk through the installation of these extensions hit, watch sass, and it opens up output here, and it's watching.

  • And it is compiling our CSS every time that we hit.

  • Save in, automatically updated with life server.

  • We go to our files here, we can see that it created a CSS directory and we have our main CSS here.

  • All right, so that is still not looking great.

  • Let's look at some CSS that is directly applicable to the home page.

  • So what we're going to do is we're going to create in the S E s s folder.

  • We're gonna create a new partial.

  • Well, name it home.

  • That s C.

  • S s all right.

  • So in here, we're gonna target our home class.

  • We're gonna set the height to 100% but a padding on the top of 40 the H.

  • So again, that's view that as a percentage, 40% of the available view port height.

  • I'm gonna set the overflow to hidden.

  • We don't want any scroll bars on the home page.

  • It should always fit.

  • We're gonna align items to center.

  • We'll do a text a line center, and then let's set our background.

  • So we're gonna have that picture.

  • That is you, Earl.

  • We need to go up one level, so dot, dot, slash image slash And then it was modeled.

  • Dash one, J peg.

  • And then we're gonna set a background size take cover.

  • All right, let's just say that and see what we have so far.

  • And we have to go back to our main and we have to import that, uh, home.

  • So import.

  • Oh, save.

  • All right.

  • So I think the images here, it's just, uh let's expand this yet.

  • So the image is actually there.

  • It's just not positioned properly yet.

  • So what we're going to do back in our home on the background, we're also going to set some positioning, so we're gonna say center top.

  • That's a little bit better.

  • Now the image is too, too bright.

  • It's too white.

  • So we're gonna put a overlay on top of it.

  • And there's several ways to do that.

  • You could use HTML mark up and then target that and create an overlay.

  • That way you could use pseudo elements, but we're actually gonna do it right here in the background.

  • So we're going to add a linear Grady int, and then we're going to say we want the Grady in to go to the right, and then we put in our colors.

  • So we're gonna use our G b a and then that takes the first part of it takes your color.

  • So we're gonna set primary color, use that variable, and then we will set this 2.9 opacity, and then we'll do another R g B A for the second ingredient value again, primary color.

  • And we could do a 0.9 again and have it the same across.

  • But we're gonna set the right side of it.

  • 2.3.

  • Then we need to come here.

  • All right.

  • Will you save this there?

  • That looks a lot better.

  • Make sure that you're still within the home class, and now we're going to target our underscore name.

  • So this is going to be the home underscored Name the AM present, Remember, AM present always refers to the parent.

  • So it's the same this typing dot home underscore name.

  • Okay, so in here, we're gonna set our font size to five.

  • Rim will set the padding on the bottom to one room margin on top of one room, and we're going to set a border on the bottom.

  • We'll set that to two pixels solid.

  • And for now, we're gonna set this to White and then within that name, remember, we have a span that goes around the last name.

  • And so that was present, Which is gonna be the same as not home.

  • Underscore Name, Dash, Dash last.

  • And we're going to set the color on here to secondary color.

  • And the font waits for an increase that went up to 700.

  • All right, let's save this.

  • It's looking pretty good.

  • All right, so when we're hovering over these icons, the color just kind of pops right in.

  • So I'm gonna add a bit of a transition to that.

  • So back in our config lets out a mix in so at symbol mixing.

  • I will name this transition.

  • He's and then we will set a transition and we'll set o point five seconds.

  • He's in and out.

  • Okay, So normally on in transition, I would target what we're trying to transition.

  • It's the color is the position.

  • What is it here?

  • We want to reuse this.

  • So when I include this mix in, I wanted to target any transition that it can set it to a 0.5 for half a second.

  • He's in and out.

  • All right, So let me say this.

  • Let's go to our main And we had a hover in our social icons right here, all right.

  • And so let's add the transition on the link so we'll do to include the mix, and we do include, and then the mix and name transition ease right.

  • Let's save this and let's hover over them.

  • You see that it's slowly changing the color.

  • It's now let's look here at our colors.

  • We haven't set the white, but in our config, we have the ability to change the primary secondary color.

  • So if we change the primary color the white, then you won't be able to see the text.

  • So what we're gonna do in our configures, we're gonna create a function that is going to give us inappropriate color for our text.

  • So to create a function due at function, this is a lot like a Java script function if you're familiar with Java script.

  • So we're gonna set this to set text color, and we're gonna pass it a variable of color, and then we're going to use an if statement.

  • So we're gonna say at symbol if and then lightness, we're going to evaluate the lightness of the color that we're passing it.

  • So if the lightness is greater than 40% then we're going to return.

  • We'll just we'll set this to black.

  • All right?

  • So if the lightness is greater than 40% so it means it's a light color than we want to return a dark color so black, and then we'll do else.

  • So if it is a dark color, we want to return white.

  • All right, so now we can use this function instead of declaring the color go back to our main here.

  • So instead of white, we're going to call set, text, color and then we're going to pass it our primary color.

  • So it's going to evaluate this primary color, which is dark and is going to return us the white value.

  • So anywhere else that we have the color set, weaken.

  • Swap that out.

  • So it's a set text color, primary color.

  • Let's see.

  • Did we set that anywhere else?

  • I think there was one other spot.

  • Yeah, on the footer set text color primary.

  • There we go.

  • We'll save that.

  • Nothing's going to change, obviously in So we also had it here on our border.

  • So this line that goes across in the middle here, we're going to set that as well.

  • Set text, color primary.

  • I think we're good there.

  • Okay, so everything's looking pretty good except for our menu, of course.

  • So let's start.

  • Let's let's get to work on our menu.

  • So let me open up the sidebar here, and we're going to create a new partial.

  • So underscore men, U S.

  • C.

  • SS and close the sidebar and let's see first was target the menu button.

  • We're gonna set that to a position of absolute set Z index here toe one right one room and top one room.

  • Okay, so we're gonna absolutely position this.

  • So I want this in the top right corner will set the heights to 20 pixels and the wit to 28 pixels.

  • And when we hover over this, we want a curse, a pointer.

  • And we're going to include our transition mixing.

  • So include transition ease, because we're going to be adding some transition animation to this.

  • All right, so within the menu button, we have our menu button burger so we can do and present underscore burger and this one, we will again position Absolute.

  • We're going to say that this one will be right.

  • Zero and top is going to be 0.5 rim the width of 28 pixels, height of three pixels, and the background will be our set text color.

  • And that's gonna be our primary color.

  • And again, we're going to include on this one hour EAS transition, all right?

  • And so let's save this and see what we have.

  • And actually, you have to remember back in remain.

  • We have to include this.

  • So imports.

  • That was menu.

  • All right.

  • And so now we have online.

  • So that's just one line.

  • Um, and so again, let's look at the HTML.

  • So the menu button is basically a rapper and we're using this.

  • We're going to be using this as our click event within the menu button.

  • We're gonna have our bars for the hamburger.

  • We just configured the middle bar.

  • And so we said, It's a 28 pixels wide, three pixels high in the background.

  • Color is going to be the text color, which is going to be white.

  • And now what we're gonna do to create the other two bars is we're going to use pseudo elements.

  • So within the burger.

  • So we're going to use an ampersand before and with the pseudo element.

  • We have our content.

  • We'll set that to nothing in a position of absolute set, the top Thio Negative eight Exel's.

  • So we wanted to move up eight pixels from its initial position, and the width will be 28 pixels.

  • Heights of three pixels, background color will be set text color, and we're going to also include our ease transition.

  • Okay, And now let's say that.

  • And now we have our top bar, all right.

  • And so now, to add the bottom bar were within the burger class Still, So we're going to use AM present after and we're basically going going to do the same thing.

  • So I'm just gonna copy this.

  • And then instead of eight pixels up, we want to go eight pixels down and I want the bottom bar to be not the same with soul.

  • Set that to 20.

  • All right, And then let's save that.

  • There we go.

  • So now we have our menu button.

  • Okay, so now on the menu button, we're going tohave it animate a bit.

  • So again, Still within the burger through JavaScript, we're going to assign it an open class.

  • So when the open class gets applied to the menu we wanted to transform and we're going to rotate 720 degrees and then we're going to set background Too transparent.

  • Let's save this for now, and we'll come back to it.

  • Let's go ahead and look at the Java script.

  • So let me open up thesis sidebar.

  • And in our distribution folder, let's create another folder named J s.

  • And then within Js.

  • Let's create a file rename that main dot Js All right, close the sidebar.

  • We'll start by targeting our Dom elements.

  • So we'll set some Constance here.

  • We're gonna set the menu button.

  • We'll use document thoughts.

  • Cleary selector.

  • Then here we can query by tagger by I d or by class.

  • So was we'll use class here and then you button was the class all right?

  • And create another constant of hamburger.

  • So the menu button again, that's the basically the wrapper.

  • Um and then the hamburger is our span.

  • So do documents, query selector and that waas menu, and then you button further.

  • Okay, so then we're going to create a variable called show menu.

  • We're gonna set that to false.

  • So initially the menu is not shown.

  • Then we will add an event listener to the menu button.

  • We're gonna listen for the click event, and then we will toggle menu will call this function that we're going to create here.

  • So we're gonna create a function toggle menu, so we'll star

Hey, thanks for checking out this video.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

初心者のためのSassチュートリアル - 超大国のCSS (Sass Tutorial for Beginners - CSS With Superpowers)

  • 7 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語