CSS - CSS Syntax
CSS Syntax
CSS Syntax is the way that elements are targeted, here is the basic CSS syntax.
selector {
property: value;
}
Selector Syntax Breakdown
selector: this is the part of HTML that we are going to target with the CSS Rule, like: div table or a class name.
property: this is the name of the property we are going to change, for example: height, width, font-family.
value: this is the setting for the property, like 100px, or "Open Sans".
; : at the end of each line after the property we have to add the ; character so that css can then be all in one line. on the last line of the selector you do not have to add the ; character but to be safe in-case additional rules are added later I find that its better to add it to every line.
Lets target something real with this example.
For this example the selector is going to be a css class.
A class is a name with a . in front of it.
my-class is a valid name so we can use .my-class to target it.
you can see in the examples below, how we add a div with the class my-class
and then target it with the css .my-class
and make the font of this bold by adding the tag font-weight:bold;
HTML
<div class='my-class'>My Class Content</div>
CSS
selector {
property: value;
}
.my-class {
font-weight:bold;
}