Fundamentals of CSS - Learn CSS - Selectors and Visual Rules Cheatsheet - Codecademy PDF
Fundamentals of CSS - Learn CSS - Selectors and Visual Rules Cheatsheet - Codecademy PDF
Purpose of CSS
CSS, or Cascading Style Sheets, is a language that is used
in combination with HTML that customizes how HTML
elements will appear. CSS can define styles and change
the layout and design of a sheet.
Selector Chaining
CSS selectors define the set of elements to which a CSS
rule set applies. For instance, to select all <p>
elements, the p selector can be used to create style
rules.
Chaining Selectors
CSS selectors can be chained so that rule sets apply only /* Select h3 elements with the section-
to elements that match all criteria. For instance, to
heading class */
select <h3> elements that also have the section-
heading class, the selector h3.section-heading can be h3.section-heading {
used. color: blue;
}
CSS ID selectors
The CSS ID selector matches elements based on the #job-title {
contents of their id attribute. The values of id
font-weight: bold;
attribute should be unique in the entire DOM. For
selecting the element having job-title as the value of }
the id attribute, a # needs to be prepended.
CSS declarations
In CSS, a declaration is the key-value pair of a CSS /*
property and its value. CSS declarations are used to set
CSS declaration format:
style properties and construct rules to apply to
individual or groups of elements. The property name property-name: value;
and value are separated by a colon, and the entire */
declaration must be terminated by a semi-colon.
/* CSS declarations */
text-align: center;
color: purple;
width: 100px;
Font Size
The font-size CSS property is used to set text sizes. font-size: 30px;
Font size values can be many different units or types
such as pixels.
Background Color
The background-color CSS property controls the background-color: blue;
background color of elements.
!important Rule
The CSS !important rule is used on declarations to #column-one {
override any other declarations for a property and
width: 200px !important;
ignore selector specificity. !important rules will ensure
that a specific declaration always applies to the matched }
elements. However, generally it is good to avoid using
!important as bad practice. .post-title {
color: blue !important;
}
Opacity
The opacity CSS property can be used to control the opacity: 0.5;
transparency of an element. The value of this property
ranges from 0 (transparent) to 1 (opaque).
Font Weight
The font-weight CSS property can be used to set the font-weight: bold;
weight (boldness) of text. The provided value can be a
keyword such as bold or normal .
Text Align
The text-align CSS property can be used to set the text text-align: right;
alignment of inline contents. This property can be set to
these values: left , right , or center .
Resource URLs
In CSS, the url() function is used to wrap resource background-image:
URLs. These can be applied to several properties such as
url("../resources/image.png");
the background-image .
Background Image
The background-image CSS property sets the background-image: url("nyan-cat.gif");
background image of an element. An image URL should
be provided in the syntax url("moon.jpg") as the value
of the property.
Font Family
The font-family CSS property is used to specify the h2 {
typeface in a rule set. Fonts must be available to the
font-family: Verdana;
browser to display correctly, either on the computer or
linked as a web font. If a font value is not available, }
browsers will display their default font. When using a
multi-word font name, it is best practice to wrap them in
#page-title {
quotes.
font-family: "Courier New";
}
li {
color: khaki;
}
Print Share