The CSS syntax is made up from three parts: selector, property and value:
selector {property: value} body {color: #ffffff} |
- The selector is normally the HTML element/tag you wish to define, like body
- The property is the attribute you wish to change like color, and font
- The value is the property value: #ffffff
HTML class tag
If you want to have paragraph (tag p) with right-aligned. You can write it like this:
HTML CODE<p class="right"> Right-aligned. </p> CSS CODEp.right {text-align: right} |
You can also omit the tag name in the selector to define a style that will be used by all HTML elements that have a certain class. In the example below, all HTML elements with class=”right” will be right-aligned:
.right{text-align: right} |
HTML ID tag
You can also define styles for HTML elements with the id selector. The id selector is defined as a # in css.
HTML CODE<p id="right"> Right-aligned. </p> CSS CODEp#right { text-align: right } Or #right { text-align: right } |