To set a div tag we type out the tag just like we would do any other tag, “<div></div>”. It is important however that you set id’s or classes to these div tags so we can target them for styling. We use CSS Cascading Style Sheets for styling our webpages. First we need to set div id’s and classes in order for the styling to work.
Syntax For Div’s
You will hear the word “syntax” a lot when it comes to coding. Syntax refers to the way a computer understands the code your are typing in. Here is an example for the syntax on setting div id’s and classes.
Setting a Div Id
Setting a Div Class
Styling Div’s with CSS
The whole reason why we use div id’s and classes is so we can style a web page. They way we target them in CSS is a little different. We target div id’s with a “#” sign. We target div classes with a “.” sign. Here are some examples.
Target a Div Id
To target a div id of “foo” in your style tag you would use this syntax.
Target a Div Class
To target a div class you would use the following syntax.
Code from Today’s Lesson
Here is the complete code that we used in the video. you can use this as a reference.
<title>All About DIV’s</title>
<div id="foo" class="goo">
<h1 class="too">All About DIV’s</h1>
<p>Div’s help us position things on our webpage.</p>
<h2>More About Divs</h2>
<p>Div’s can be targeted with CSS and styled.</p>
Things To Do
If you have not already done so be sure to subscribe so you get the latest lessons on beginner coding. You will see the subscribe box on the bottom and to the right of this page. Be sure to subscribe to our YouTube channel and follow us on Facebook and Twitter.
Our Next Lesson
In our next lesson we will be going over tables and how they work in a webpage.