ID's and classes are used with div tags to basically give the tags a name.
ID's are written with a hash at the beginning, so the code <div id="box"></div> would create a div tag with the ID 'box'. In the style, the ID would be written as #box.
Classes are written the same, but with a period instead of a hash, so it would be written in the style as .box
The major difference between them is that classes are used to group things together. For example, and ID can be used to define the size of a div tag on a single page, whereas a class could be used to choose the font style, or font size that will be used on every page.
You could just choose the font and font style etc. in every single ID of a box on every single page, but that adds unnecessary lines of code to each style, when only a single line of code could be used with a class.
When making my last website, I made the mistake of not using any classes, which made the file size of my CSS document a lot bigger than it could have been, which, in turn, will increase the loading time of the web page and driving away a potential customer.
This time, I will pioneer the use of classes to ensure I have a website that loads quickly, and is also a lot neater.
No comments:
Post a Comment