Visual Rules
Visual Rules
The purpose of CSS is to add style to web page, and each element on the page can
have many style properties. Some of the basic properties relate to the size, style, and
color of the element.
Font Family
To change the typeface of text on your web page, you can use the font-family
property.
h1 {
font-family: Garamond;
}
• The font specified must be installed on the user’s computer or downloaded with
the site.
• Web safe fonts are a group of fonts supported across most browsers and
operating systems.
• Unless you are using web safe fonts, the font you choose may not appear the
same between all browsers and operating systems.
• When the name of a typeface consists of more than one word, it’s a best
practice to enclose the typeface’s name in quotes
h1 {
font-family: 'Courier New';
}
Font Size
To change the size of text on your web page, you can use the font-size property.
p {
font-size: 18px;
}
Font Weight
In CSS, the font-weight property controls how bold or thin text appears.
p {
font-weight: bold;
}
If a certain section of text was required to appear normal, however, we could set the
font weight of that particular element to normal, essentially shutting off bold for that
element.
Text Align
The text-align property will align text to the element that holds it, otherwise known
as its parent.
h1 {
text-align: right;
}
• left — aligns text to the left side of its parent element, which in this case is the
browser.
• center — centers text inside of its parent element.
• right — aligns text to the right side of its parent element.
• justify— spaces out text in order to align with the right and left side of the
parent element.
h1 {
color: red;
background-color: blue;
}
Opacity
Opacity is the measure of how transparent an element is. It’s measured from 0 to 1,
with 1 representing 100%, or fully visible and opaque, and 0 representing 0%, or fully
invisible.
Opacity can be used to make elements fade into others for a nice overlay effect.
.overlay {
opacity: 0.5;
}
Background Image
CSS has the ability to change the background of an element. One option is to make the
background of an element an image.
.main-banner {
background-image: url('https://www.example.com/image.jpg');
}
.main-banner {
background-image: url('images/mountains.jpg');
}
Important
p {
color: blue !important;
}
.main p {
color: red;
}
One justification for using !important is when working with multiple stylesheets. For
example, if we are using the Bootstrap CSS framework and want to override the styles
for one specific HTML element, we can use the !important property.
Review