02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Inline CSS Styles

Until now all of our styling was done globally to the whole page or every single tag. In this section of our session we will look at how to add specifically to a tag some styling using the style attribute.

Video Transcript

00:00Alright,
00:00So before we are done with the overview topic of CSS
00:03which is a big topic, it’s just as big as HTML
00:07and probably even bigger than that
00:09I wanted to be able to show you that there’s a few different ways of styling
00:13One way is the way we did it,
00:14we set our style attributes on the top of our page,
00:16in our header and that controls the information inside of our page.
00:20There’s actually two other ways.
00:22The second way of doing it is E.g. going to a specific paragraph <p&gt;
00:27pressing on the space and then adding the word ‘”Style=”
00:30By adding the word Style we can then directly put style
00:33into a paragraph or into any HTML attributes
00:36So let’s say in this case we want to change the background,
00:39and we want to set the background to be, let’s say …
00:42Let’s pick one of the backgrounds in our Photoshop again
00:46so we’re just going to pick your.. Let’s say we’ll go for grey.
00:53I didn't grab the color.
00:55Grab the color, go back into our editor
00:57and in our editor I'm just going to set the value of background
01:01background,
01:02and if I go into my browser now that it’s saved
01:08then you’ll see that I’ll add a background into my copy.
01:11Not very visually pleasing but it’s doable.
01:14Now one thing that I want to say about that,
01:16even though I'm showing you how to do it,
01:17now that you know how to do it, Don’t do it
01:21it’s really...the only time you’d want to use that
01:23is maybe when you are sending email newsletters and not a website
01:26because really one of the biggest problems
01:27with setting CSS directly to HTML inside of the page
01:31is that it mixes everything up.
01:33And the whole idea
01:33of making HTML separate and CSS separate
01:37is so you can use things over and over
01:39and if you’re doing a style
01:40that is deliberately connected to a specific element
01:43it’s not really usable throughout your website,
01:45it’s only usable in that specific paragraph.
01:47So if you wanted to do another styling in that background
01:50you’d have to actually do it all over again
01:52making your file sizes bigger and on the other hand
01:55also making it much harder to manage
01:57because now you have to go inside of your HTML,
01:59inside of your document itself to update information.
02:02So traditionally we say anyone that teaches it
02:04and anyone that really does it for a while
02:06is try to avoid using inline styles.
02:08Once in awhile you might get into a scenario that you have to
02:11but 99% of the time you want to avoid it.
02:14-Alright? -Yeah
02:15Cool.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!