1. Home
  2. Explore
  3. Computer Science
  4. HTML & CSS Basics to Pro

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

HTML & CSS Basics to Pro

Transcript

Welcome to the complete HTML and CSS course. In this course, we're going to learn how to build websites from a beginner to a professional level, and by the end of this course, we're going to build youtube.com. Now you don't need any previous coding or technical experience. This course is designed to be your first step to becoming a software engineer. We're going to start from the very basics of HTML and CSS and build our way up step by step. And along the way, we're going to learn all the major skills that we need to create websites at a professional level. You can find the different sections of this course below the video here and here. And after each section, I'm going to give you a bunch of exercises that you can do on your own to practice the skills that we learned in total. This course is going to have more than 100 exercises. Lastly, you don't have to worry about taking notes.

I created an HTML and CSS reference that will list everything that we learned in this course. With that said, let's get started. I am going to be doing this course on a Mac, but everything is the same for a Windows computer. Before we begin, we're going to need two pieces of software, a web browser and a code editor. A web browser lets us view websites on the internet. It's also going to let us view the website that we create in this course. The most popular web browser for web development is Google Chrome. A code editor helps us write our HTML and CSS code. The most popular code editor for web development is called VS.

Code or Visual Studio Code. To install both of these, we can go to google.com and then search for Google Chrome or for VS code and then open the first result and follow the instructions to download and install. Once we have those two installed, we can start the course. We'll begin by learning what is html. HTML stands for hypertext markup language. You don't have to worry about what that means. Just know that it's a tool that we use to create websites. Every website from YouTube to Google to Amazon uses a combination of HTML and CSS to create everything that we see on the website.

The easiest way to understand what HTML is, is that we're simply giving instructions to a computer. We're telling the computer what to do step by step. The computer will then follow our instructions to create our website. So I find the best way to learn HTML is to jump in and give it a try. So we're going to create our first HTML file and our first website. Let's go to our computer and we're going to create a new folder. So this folder is going to contain all the code for this course. I'm going to call this HTML dash CSS dash course.

Next, we're going to open this folder in our code editor. So I'm going to open vs code, and then I'm going to click file open and I'm going to find the folder that we just created, which is this one. Now once that's open, you should see the folder name at the top here and on the side here. Now let's create our first HTML file. We're going to click this icon to create a new file and we're going to call this file website dot html.

So we have to make sure that this file ends with html. This tells a computer that this file contains HTML code rather than just text. So as I mentioned, HTML is basically some instructions you give to the computer. We're going to learn our first instruction, which is less than button greater than, and we also need to type lesson slash button greater than, but our code editor might auto complete this for us. So this is an instruction to create a button and inside the button we're going to have the text. Hello.

Now let's save our file and we're going to learn how to open this in our web browser. To open our new website, we're going to go to the folder that contains our code. We're going to find our HTML file. We're going to right click open with Google Chrome. And now you can see that we have our first website that has a button with a text Hello inside. And if we look back to our code, that's exactly the instruction that we gave to the computer. So as you can see, HTML is pretty straightforward. It's pretty easy to understand what's going on.

Now let's try another instruction. We can give to the computer on a new line. We're going to type less than P, greater than, and we also need to type less than slash p greater than, and our code editor might auto complete this for us too. So the P here stands for a paragraph. This is a paragraph of text. Inside our paragraph, we can put some text. So let's put the text paragraph of text. Now we can save this and to get our website to reflect our most current code, we're going to go to our webpage and refresh. And now you can see that our website is displaying a paragraph of text just like we told the computer to do.

So that's basically how HTML works. The computer reads our HTML code from top to bottom and then follows those instructions and creates a button and a paragraph of text. If we reverse the order of these lines, for example, if I put the paragraph up here and I save it and refresh the page, then the paragraph will appear on top because again, the computer is just following our instructions one by one.

Now I'm going to introduce some terminology. So each of these things that we're displaying on the webpage is called an HTML element. So a button is a type of HTML element and a paragraph is another type of HTML element. So element is just a generic term that we use to describe anything that we can display on the webpage, and we're going to be using this term element throughout this course. So now I want to explain why we have to write all of these symbols that's less than this, greater than, and this less than slash This is something called syntax. Syntax are the rules for how a coding language like HTML should be written. If you think of a language like English, we have something called grammar, which is the rules of the language. Syntax is basically the same thing except for coding languages. Now, the biggest difference between a language like English and a coding language is that in English, you don't have to follow the rules of grammar perfectly.

People can still understand you, but in a coding language, if you don't follow the rules of syntax, the computer won't understand your code. For example, let's break the rules of syntax by deleting this greater than symbol, and now we're going to save our file and we're going to go to our website and refresh. And now you notice that our button is gone, and that's because we're not following the proper syntax. So the computer doesn't understand our HTML code anymore.

So let's put that greater design back so that we're following the proper rules of syntax and we don't need this. So let's save and refresh our page. And now our button is back because we're following the rules of syntax. So what exactly are the syntax rules for H T M L? So this part of the code is called an H T M L tag. It basically tells a computer what we're trying to create. We write a tag by writing the less than symbol. This is the tag name, which tells a computer what kind of element we're trying to create, and then the greater then symbol. So every element consists of two tags in opening tag and a closing tag. The closing tag is the same as the opening tag, except it has a slash in front of the tag name.

That's how you can tell it is a closing tag. You can think of the opening tag as the start of the button and the closing tag as the end of the button. And then in between is a content or the text inside the button. And the same thing for the paragraph. The paragraph has an opening tag, a closing tag, and some content inside the paragraph. So as long as we follow these syntax rules for html, we have an opening tag and a closing tag, and the closing tag starts with a slash in front of the tag name. Then our computer will know what to do and display our elements on our webpage.

The next element that we're going to learn is a link to another website. For example, if we go to Google and we search for something on Google, it will give us a bunch of links and when we click these links, it will take us to another website. So we're going to learn how to do that in our HTML code. So we'll go back to our website here and in our code we're going to type less than a greater than. So this A here represents an anchor element. An anchor is basically a link to another website.

So inside this anchor we're going to put the text of our link. So let's put the text as link to YouTube. We're going to save this and the refresh, and now we have a link, but if we click this, it doesn't actually take us to YouTube, and that's because we haven't told the computer where this link is supposed to take us. Right now we just have a link without a destination. So to set a website to link to, we have to learn a little bit more HTML syntax. So we're going to go into the opening tag and we're going to type space HREF equals double quotes, double quotes.

So inside these quotes we're going to copy and paste YouTube's website url. So to get that we can go to our webpage and then type in youtube.com. And at the top here we have the url. So we're going to copy this and paste this into our quotes. And now we're going to save our file. We're going to go back to our website and refresh. And now we have a link that we can click. So when we click this link, it's now going to take us to youtube.com. So that's how we create a link to another website with html.

Now let's go back here and explain what this syntax means. So this is called an HTML attribute. An attribute basically modifies how an element behaves. In this example, we are using the href attribute and it determines where this link element will take us When we click it right now it's going to youtube.com, but if we change this, it will take us to a different website. So this attribute is modifying how the link element behaves. So the syntax rules for an attribute are we have to have a space between the attribute and the tag name. Otherwise, if I write href here, the browser is just going to think that this whole thing is a tag name. So that's why we have to have a space. So then we're going to have an equal sign and double quotes. So the text to the left of the equal sign is known as the attributes name, and on the right side is the value. The value must be surrounded by

double quotes as you can see here. So you can kind of think of it like this. The name tells us what we're modifying. The value tells us what we are modifying it to. So the H tells us we're modifying the destination of this link and we're modifying it to youtube.com. We can also have multiple attributes on an element to add another attribute, we just separated with a space like this, and now we're going to add another attribute to our link element, and this one is called target.

So the target attribute determines whether this link opens in the current page or in a new tab. So by default, if we don't have a target attribute, it opens in the current page like this. But if we set the target attribute to underscore blank, now this link element will open in a new tab. So let's go to our webpage and refresh and click this link. YouTube will now open in a new tab.

So by using attributes we can modify different parts of this element's behavior. The H RF attribute modifies where this link goes and the target attribute modifies whether this link opens in a new tab or in the current page. Keep in mind that the h r and target attributes only work on the link element. The button and the paragraph elements have their own set of attributes that we can modify, and we're going to learn these later on in the course. But for now, I just wanted to introduce you to the idea of using attributes to modify our HTML elements.

The last thing we're going to learn in this lesson is some weird quirks of the HTML syntax. So something that a lot of beginners have trouble with is that in html, if you have multiple spaces like this, for example, if we save this file and we reload, you'll notice that all of these spaces just appear as one space on the website, and that's because according to the syntax, extra spaces are essentially ignored. So beginners usually have trouble with this because for example, if they want to add space between this button and this link, they would start adding spaces in front of the link thinking that it will move it away from the button. So if we save this and we refresh, nothing happens. And that's because all of these spaces are essentially ignored in html.

So later in the course, we're going to learn how to deal with these situations, but for now, just keep this in mind. So let's get rid of these extra spaces for now. And another weird quirk of the syntax rule is that if I put my cursor here and I press enter to create a new line and I put my cursor here, again, these new lines also count as spaces, so the browser essentially ignores them. If I save the file and reload, you'll see that the new line doesn't do anything.

So this actually makes organizing our HTML code very flexible. For example, if I wanted some more space between these elements so that it's easier to read in my code, I can just add as much spaces as I want and it won't get reflected in the website because extra spaces like these new lines are just ignored. A lot of people like to put the content of the element on its own line like this so that the tags basically align with each other in the same column.

And same thing for here. You'll notice that this line is really long. We can actually add new lines here to make our code easier to read. So when we organize our code like this, we generally indent or add spaces in front of these lines. This helps us clearly tell the difference between the elements, tags and its contents. If we didn't have this indenting, then it's pretty hard to tell where this element starts and where it ends, especially when we have a lot of code. Now your indents might look a little different from mine. It might look something like this where you have more spaces than I do. This happens because by default vs. Code uses four spaces per indent. Generally in HTML and css, we use two spaces per indent.

To update this, we're going to go down to this bottom toolbar and click this section, and then we're going to click indent using spaces, and we'll change this from four to two. So now this file is going to use two spaces per indent, so we can get rid of this and press tab to have proper indenting. Now that only affects it for the current file. We can change it for every file going forward by going to the bottom left here and clicking this icon and then going into settings.

And in here we're going to search for tab size, and I'm going to scroll down and we'll change the tab size from four to two. All right, so we just learned the basics of html, how to write HTML code, and then turn that into a website. We also learned how to write HTML attributes which modify the behavior of an element, and we learned about syntax, which are the rules that we had to follow when writing our code.

Here are some exercises that you can try on your own to practice what we learned in this lesson. Feel free to pause the video here if you need to. You can find these solutions as well as more exercises on my website. Super simple.dev. The link is below the video. In this lesson, we're going to learn CSS or cascading style sheets based on the name. It's used to style our webpage, so it's used to change the appearance of our H C M L elements.

So I've actually prepared a project that we can do in this lesson. So we're going to open this project by going to super simple.dev/exercises/buttons. So on this webpage I have some really nice looking buttons from famous websites, namely YouTube and Twitter that we can copy and practice our CSS with. So we're going to go into our code and we're actually going to create a new file for this exercise.

So let's create a new file and let's call it buttons dot html. And we're going to open our new HTML file in our browser. So that's open the folder that contains our code. We're going to right click open with Google Chrome. And now I'm going to set this up by moving our reference design to the bottom like this so that it's easier for us to copy it with css.

I'm just going to move that to the corner and then we can work here. So first, let's work on creating the subscribe button. So just like we learned before, we're going to create a button using H T M L, so less than button, greater than, and then insider button. We're going to have the text subscribe. And now let's save and refresh our page. And now we have our button.

Next we're going to start changing the appearance of this button so that it looks like the subscribe button from YouTube. Let's go into our code and we're going to start writing some CSS to change the appearance of this H T M L element. So to write css, we have to create a new element called a style element. So this style element is unique in that it doesn't appear visibly on the page. So for example, if we save our file and then we reload the page, the style element doesn't actually create anything.

So the purpose of this element is that inside this element we can write CSS code which modifies the appearance of other elements. For example, let's write our first bit of CSS code. We're going to type button open squiggly bracket, close squiggly bracket. And then inside these brackets, we're basically going to give instructions to the computer on how to modify the appearance. For example, we can set the background dash color red and semicolon.

So make sure that you write this out exactly as I have it here so that we're following the syntax rules for css. So let's save this file and refresh our page. And now you can see that we set the background color of the button to red. So as you can see, c s s is similar to H T M L. We're simply giving instructions to the computer and then the computer follows our instructions step by step. And just like H T M L, we have to follow certain syntax rules when writing our CSS so that the computer understands our code.

So what are the syntax rules for css? How does this code work? So the word at the front here is called a CSS selector. It tells a computer which elements on the page we are targeting with our CSS code. In this case, we are targeting all buttons on the page and we're going to change the background color of all buttons on the page to red. Now, inside these brackets, there are other rules that we have to follow. The text to the left of this colon is called the CSS property. It tells a computer what we are changing to the right of the colon is the CSS value. It tells a computer what we're changing the property to. In this case, we're changing the property background color to red, and that's exactly what the computer did. The colon is here to just separate the property and the value and the semicolon here is just like a period in English. In English, you end sentences with a period in css,

you end a style with a semicolon. So that's what all of this syntax means. So we can actually add multiple styles inside these brackets. So let's go ahead and add another style. We're going to change the text color to white to match this design. So the property for changing the text color is called color. So notice that it's not called text color, it's just something that we have to remember. We're going to change it to white and we'll end it with as semicolon. Let's save and refresh. And now you can see that we change the text color of this button to white.

And that's basically how c s s works. We tell the computer what we're targeting and then we give some styles and the computer is going to apply these styles one by one. So let's do another example. This time we'll set the border property. So notice that our button has a border while the subscribe button here doesn't have a border. So we're going to set the border property colon two, none, and we're going to save this file and refresh. And now we just remove the border. So if you look at our styles here, it's actually pretty straightforward. They're pretty easy to read. We set the background color to red, text color to white and border to none. So just like html, CSS is pretty straightforward. We're essentially just giving the computer instructions.

So the general technique for going from something that looks like this to something that looks like this is to just change these styles one by one. So we're going to continue changing styles one by one until we get our design here. The next style I'm going to change is the height. So our button's a little bit short, I'm going to make it taller. So I'm going to set the height to something like 50 px. The PX here represents pixels. Pixels are a very common unit of measurement in the digital world, image sizes are measured in pixels, video sizes are measured in pixels, and your screen sizes also measured in pixels. In this case, we're going to set the button high, two 50 pixels. And don't worry too much about knowing what 50 pixels looks like. The more that you write CSS and work with pixels, the more you get a sense for how big these measurements turn out to be.

So for now, let's save this file and refresh the page. And now we have a button that is 50 pixels tall, but it actually looks like it's a little too tall. So I'm going to change the heights to something like 30 pixels, and I'm going to refresh the page again, and I actually want it to be a little bit taller, so I'm going to change it to maybe 36. I'm going to refresh and I think that looks pretty good to me. So you see that in css. We do a lot of trial and error to get our measurements right Now let's keep working step by step to get to our design. Next, we're going to adjust the width.

So let's change this to something like a hundred pixels. Let's see how that looks. I'm going to save it refresh, and I think it looks a little bit too small, so I'm going to increase it just a little bit. 1 0 5 and refresh. Okay, I think that looks good enough for me. Next we're going to change the background color because currently our red is not the same as our design. So VS code has a really nice feature which is a color picker. So if we hover over this color box here, it gives us access to a color picker that we can pick another color with. So I'm going to pick something that's a little closer to what I see at the bottom, and don't worry, it doesn't have to be perfect. I'm going to pick something like 200 0 0.

I'm going to save this and refresh. Okay, so I think that looks close enough. So you might be wondering what this value means. We went from a color of red to RGB 200 0 0. So this RGB value is another way of measuring color. It's a more precise way of measuring color than just using a word like red or white. So the way that RGB works is that pretty much every color can be created using a combination of red, green, and blue. So that's what this syntax represents.

The R represents how much red we have in this color. G represents how much green and B represents how much blue. And these three numbers represent how much red we have, how much green, and how much blue. The minimum value is zero and the maximum value is 255. So if we removed all the red and green and we just have maximum blue and we save, that's going to get us a blue color.

On the other hand, if we have all green color and we get rid of the blue, we're going to have a green color. So this is basically how RGB works. It's a combination of red, green, and blue to create any color that we want. Now, don't worry too much about knowing what an RGB value looks like. For example, if you have a random value like this, if you gave this to me, I wouldn't even know what this color was. Usually I just use the color picker to pick the color that I want and then it will give me the RGB value that I need.

The only RGB values I suggest you remember are if we set all the colors to the maximum value. So 2 55, 2 55, and 2 55, this creates white. So we save it and refresh that creates white. If we set all of these three to zero, that creates black and we refresh, that creates a black color. So now let's go back to what we had before, which I think was 200 0 0, and we'll save and refresh.

And the next thing we're going to change is here. We might not be able to see it, but if we zoom in here, this button has rounded corners while our button has pointy corners. So to make rounded corners, the CSS property for doing that is border dash radius, and the border radius takes a pixel measurement. The higher the pixels, the more round the corners will be. So for now, let's try colon two pixels and save. Now if we refresh the page, our button now has rounded corners just like our design. So I'm going to zoom back out and zoom back out.

So the last thing I'm going to change is if we hover over this button, you'll notice that our mouse turns into this sort of hand. This hand is called a pointer. So we're going to change the cursor, the mouse. This thing that you point around is usually called the cursor, and we're going to change the cursor to a pointer. Let's save and refresh. And that's how you get this hand whenever your mouse is over this button. So that's basically how we go from a basic HTML button to something that looks more professional. We create the button with html, and then we set the styles one by one. Now you might be wondering, how do I know all of these CSS properties? How are you supposed to memorize all of these?

So usually when I don't know the CSS property for something, for example, if I want to create rounded corners, I would go to Google and search something like CSS and what I want to do, so let's say I want round corners, and usually the first few links give some really good suggestions on what the property is. So here, right away we have the border radius property in the first link and it gives us some sample code that we can use.

So that's how I discover all of the CSS properties. I look at a design and I ask myself, okay, what do I need to achieve this design? And then I search for it in Google. So don't worry. As you use CSS more and more, you're going to have to Google things that you don't know and you're just get used to the process of finding answers by searching for them. But for the purposes of this course, I'm going to give you a lot of these CSS properties so that you can get some good practice with them. The next step we're going to do is to copy this join button. So let's create a new button on our page with html,

and this is going to be the join button. So we're going to put the text join inside this button, let's save it and refresh. And unfortunately, it looks like our join button looks like the subscribe button, and that's because in our C s s, this word button means that all of these styles are targeted to all buttons on the page. So how do we get these styles to only target the subscribe button? So we're going to learn a new HTML attribute that we can use for this.

So remember in the previous lesson we learned that attributes modify the behavior of elements. In this lesson, we're going to learn a very useful attribute that is used a lot in css. We're going to go to the opening tag again, and we're going to add a new attribute called the class attribute. So we're going to type class equals quotes. Quotes. So the class attribute basically lets us label HTML elements. For example, let's label this button the subscribe button.

And also my code is getting a little long for this line, so I'm going to put the text on a new line to make it easier to read. So remember, according to HTML syntax, these extra spaces don't matter. They're ignored. So now that we set the class attribute, we've essentially set a label to this button and we can target this label in our css. So to target a class in css, we can start with a dot, and then we're going to type out the class name. So we're going to type out subscribe dash button.

So according to CSS syntax, if we start this code with a dot, that means we're going to target a class name instead of an element name like button. So here we're going to start targeting just any element that has the class subscribe button. So if we save and refresh now you'll see that all of these styles only apply to elements that have the class subscribe, and our join button does not have any of these styles. Now, multiple elements can have these same class. So for example, if I set the class of the join button to subscribe dash button,

all these styles will be applied to any element with the subscribe button class. That's what this dot means. And that means these are going to be applied to this and this. So if we save and refresh, now the join button has these styles again because it has a class of subscribe button. But for our purposes, we actually want this to have a different set of styles. So let's give a different class to the join button. We're going to give the class join, and I'm also going to reformat my code a little to make it easier to read. So let's save and refresh.

And now we're back to where we can start modifying our join button. Now let's start styling our join button to match our design. So remember, the general strategy is to create the element with HTML like this and then style it one by one until you match your design. So first we're going to target the class. That's what this dot means. We're going to target the class join dash button. Okay, so let's set the background dash color to white.

Let's save it and refresh. And next, let's deal with the border. So our border is a little bit gray. We can set it to maybe border dash color to blue, and let's see how that looks. Let's save it and refresh. Okay, so it looks a little darker than what we have in our design. Let's go into our color picker and pick a more accurate color. So I'm just going to do this by eye. Don't worry if it's not totally accurate. We're just trying to get something that's close enough. I'm going to go over here and I'm going to pick something like maybe something like this. Let's save it refresh, and that's a little bit too dark. So I'm going to pick something a little bit lighter,

save it and refresh. Okay, I think that's pretty good. But we also noticed that our border's a little weird. So on the top it looks like it's a darker, it's a lighter shade of blue, and at the bottom it's kind of a darker shade of blue. So to fix that, we're going to set the border style to be a solid color. Let's save this and refresh. And now we get a solid color all around.

The next thing we can change is our border looks a little bit thick compared to the design, so we're going to change the border dash width. So you'll see that a lot of these styles are pretty self-explanatory. So we're going to set the border width to let's say one pixel. Let's save it and refresh. Okay, so that looks pretty good. Next we're going to set the tex color. So we're going to set the tex color to blue and have it the same as our border. So remember, the property to set Tex color is called color colon, and we're going to copy this color down here, save it and refresh. Okay, so that looks, it's a little light, but I think it's okay.

Now we're going to set the height and the width. So let's set the height to be something like 36 pixels to match our subscribe button refresh. Okay, and now we're going to set the width. So let's try, I don't know, 60 pixels. Let's see how that looks. Save and refresh. Okay, I'm going to set it to maybe 62. Okay, let's save and refresh. And again, we're going to set some rounded corners. So that is border dash radius, two pixels. We're going to save it and refresh. And now we're almost there to matching this design.

The last one we're going to set is cursor pointer to get that nice hand pointer when we're hovering over the button. So refresh now when we're hovering over the join button, we have this nice pointer icon. So another thing we notice is that there's a lot of space between these two buttons and there's not a lot of space between ours. So in CSS space is called margin. So to add space, we're going to add some margin. So let's go to the subscribe button styles. And we're going to add some margin dash, right?

So we're going to add some margin or some space to the right of this button. And we're going to set this space to maybe eight pixels. Let's see how that looks. Save and refresh, and that looks pretty good to me. So now we're done with the join button. Lastly, we're going to create this tweet button. Let's go back into our code. And remember, our general technique is to number one, create the element with html, and then number two, style it with CSS one by one. So we're going to create a button with a text tweet. I'm going to move my editor a little bit to the right here so we can see it. I'll move this here as well.

And let's refresh your page. So now this button has the same style as a join button because it has a join button class, and that's being targeted up here. So instead of the join button, we're going to give a class or a label of tweet button. Now save and refresh. And now we're back to the default styles. So in our css, we're going to write some code. We're going to target the class. So we start with a dot. To target a class, we're going to target the tweet button class.

So just like our other buttons, we're going to adjust the style of this button one by one until we match our design. So let's start off with the background dash color. That set us to blue to start off with. Now I'm going to try my best to match the Twitter blue that we have here. So I'm going to pick something like this, and I think that looks pretty good. Save it and refresh. Okay, we'll leave it like that for now. We might adjust it later. Let's change the color now to white.

So that'll change the text color. Okay, let's get rid of the border refresh and save. Let's give it a height of 36 pixels to match our other buttons. And the color's a little bit off, so I'm going to adjust it just a bit. Maybe it should be a little more like this. Save it refresh. Okay, I'm pretty happy with this. Now we're going to adjust the width to maybe 105. Let's see how that looks.

Okay, that's a little too much. Let's adjust it to 80. Let's adjust it to 70. So as you can see, there's a lot of trial and error when we're working with c s s. Now, to get this rounded effect, we can set a border radius. Let's start with two pixels. If we refresh, we get rounded corners. If we start increasing the pixels for the border radius, let's save and refresh. It starts getting rounder and rounder.

So the trick to getting these round buttons is we have to set the border radius to half the height or the width, whichever is lower. So in this case, the height is 36. If we set the borderer radius to half of that, which is 18, save and refresh. That's how we get this rounded color. The last thing we're going to do is to bold the text in here. So in our design, this tweet text here is very bold, so we're going to make our font bold as well. So do that. We're going to set this property called font dash. Wait, I'm going to set it to bold save and refresh.

Okay, looks pretty good. It looks like this font is actually a little bigger than ours. So let's actually set the font dash size, set it to maybe 15, see how that looks, save and refresh. Okay, I think that looks pretty close. I'm going to change the width to maybe 74. See how that looks? Okay, so I think this is good enough. Currently we're just trying to copy things by eye. Later. I'll show you a technique of how to copy these colors and measurements exactly, but for now, it's good enough to be able to achieve these designs just by looking at them.

So the last thing for this button is to add the cursor pointer. Let's save it and refresh. So if we hover over this button, we now get a nice pointer for our cursor. So the last thing I'm going to adjust here is the spacing between these two buttons. Remember, spacing and CSS is called margin. So we're going to add to the join button. Actually, let's add it to the tweet button just for practice. We're going to add spacing. So we're going to add margin to the left colon, and let's make it eight pixels like we had it for the subscribe button.

Let's save it and refresh. And there we go. So we took our basic buttons and we were able to copy these really nice looking designs just by looking at them. And the technique that we use for doing this is first we create the element with html, and then we style it with CSS one by one until it looks close enough to our design. So here are a bunch of exercises from other popular websites that you can try out for yourself. This is a good challenge for you to be able to look at a website by I and use CSS to copy the styles that you see.

In this lesson, we're going to learn some intermediate CSS skills, such as how to create hovers, transitions and shadows. For most buttons you see on the internet, if we hover over them with our mouse, they change their style slightly, some of them get darker, some of them get lighter. We're going to learn how to do that in our code. So we're going to use the same exercise as before. As a reminder, you can find it at super simple.dev/exercises/buttons. These buttons, when we hover over them, they actually change their style. So this is going to help us practice learning about hovers. In addition, you'll notice that if we hover in and out, they change their style smoothly so we can also learn about transitions. And lastly, this tweet button, if we hover over it, it casts a little bit of a shadow, so that'll help us practice shadows.

But first, let's work on the hover styles for the subscriber button. Let's go into our code and find the styles for the subscribe button, which is everything here. And now to create a hover effect, we're going to create a new block of css. We're going to use a.to target a class. So this time we're still targeting the subscribe dash button, but this time we're going to add colon hover, open bracket, close bracket.

So inside these are styles that will apply only when we hover over the button. That's what this colon hover means. For example, we can set the background dash color two green. Now let's save our file and refresh the page. And when we hover over this button, you'll notice that it's green. So the way that this works is that if we are not hovering over, all of these styles apply. So the background color is red. If we are hovering over the button, these styles now apply in addition to these styles. So we're essentially adding extra styles when we hover. So this colon hover is known as a pseudo class.

It basically adds extra styles in a certain situation. So in this case, it's going to add extra styles when we hover. Another example of a pseudo class is dot subscribe button colon active. So the active pseudo class activates when we click on the element. So when we click on the button, we can set the background dash color to blue. Let's save this and refresh. Now when we hover over, we're going to apply these styles. So the background color is going to be green, and then when we click, we're going to apply the active styles, and then the background color is going to be blue.

So let's look at our design and see what kind of hover styles we have. Let's refresh. So when we hover over our subscribe button, it seems to turn a little bit more light, and if we click it, it becomes even lighter. So the way to make our button lighter is using a new property that I'm going to introduce. So let's get rid of these for now. Let's save and refresh. So we got rid of those pseudo classs styles.

We're going to set a CSS property called opacity. So opacity tells us how SeeThrough and HTML element is. It takes a value between zero and one. A value of one means that this element is completely normal. So if we save this and refresh, you can see that if we hover over it, it's completely normal. And as we decrease the opacity, let's decrease it to 0.7.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent