So, we can style different elements in our webpage by using inline styles.
We can also style using an internal style section in our web document.
Here is an example web document:
<html>
<head>
<style>
p{
color:red;
font-family:Tahoma;
}
img{
border:red solid 1px;
border-radius:5px;
}
</style>
</head>
<body>
<p>This is a web page.</p>
<p>I hope you like it.</p>
<img src = "happycat.png"/>
</body>
</html>
What if I want some of my web document elements to follow a style rule, but not all of them?
For example, I want some of my <p> tags to be blue, not red.
Just put an inline style into the element you want to be different eg:
<p style = "color:blue;">This is a web document!<p>
This is a good answer if there are only a few elements you want to change. However, what if there are many p tags you want to be blue? And then you change your mind! You want some p tags to be purple instead!
You will have to change blue to purple in a lot of elements and this takes time and can be frustrating!
Design a rule in the <style> section of your page.
Then apply the rule to elements in your webpage!
Style rules in CSS are called classes. So, let's design a class:
<style>
p{
color:red;
font-family:Tahoma;
}
img{
border:red solid 1px;
border-radius:5px;
}
.bigRed{
color:red;
font-size:36px;
}
</style>
Note:
Now that we have designed a class, we can apply it to any element in our web document. Here is an example:
See the Pen introToClasses by Mister Moosi (@mistermoosi) on CodePen.
First, let's set up a project folder for Focus 8.
Download these 4 images and save them in your project folder.
Download this html file and save it in your project folder. Open it in a web browser eg Chrome or Firefox or Safari or Explorer
Follow these instructions carefully.
Hi, this is Bob!
If you need to contact us, call plus four four zero seven six five two three eight six two four.
Alternatively, you can email be at bob at bobthebuilder dot com
We are here to serve you!
Do you have any more ideas? Add more content and/or style your page as you like. Create a new class and apply it whereever you want. Don't forget to use W3 Schools for ideas!
Submit your project folder as instructed by your tutor.
browser file tags body save h1 html h4 folder structure refresh image organisedexport embed