Learn CSS - Selectors and Visual Rules Cheatsheet - Codecademy
Learn CSS - Selectors and Visual Rules Cheatsheet - Codecademy
●
type attribute to de ne the type of content being linked
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 de ne styles and
change the layout and design of a sheet.
Selector Chaining
CSS selectors de ne 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.
!important Rule
The CSS !important rule is used on declarations to override any other
#column-one {
declarations for a property and ignore selector speci city. !important rules
will ensure that a speci c declaration always applies to the matched elements. width: 200px !important;
}
However, generally it is good to avoid using !important as bad practice.
.post-title {
color: blue !important;
}
Chaining Selectors
CSS selectors can be chained so that rule sets apply only to elements that match
all criteria. For instance, to select <h3> elements that also have the /* Select h3 elements with the section-heading class */
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 contents of their id
#job-title {
attribute. The values of id attribute should be unique in the entire DOM. For
font-weight: bold;
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 style properties and construct rules to apply to /*
individual or groups of elements. The property name and value are separated by CSS declaration format:
a colon, and the entire declaration must be terminated by a semi-colon. property-name: value;
*/
/* CSS declarations */
text-align: center;
color: purple;
width: 100px;
Font Size
The font-size CSS property is used to set text sizes. Font size values can be
many di erent units or types such as pixels. font-size: 30px;
Background Color
The background-color CSS property controls the background color of
elements. background-color: blue;
Opacity
The opacity CSS property can be used to control the transparency of an
opacity: 0.5;
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 weight (boldness) of
font-weight: bold;
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 alignment of inline
text-align: right;
contents. This property can be set to these values: left , right , or
center .
span {
color : green ;
}
Resource URLs
In CSS, the url() function is used to wrap resource URLs. These can be
background-image: url("../resources/image.png");
applied to several properties such as the background-image .
Font Family
The font-family CSS property is used to specify the typeface in a rule set.
Fonts must be available to the browser to display correctly, either on the h2 {
computer or linked as a web font. If a font value is not available, browsers will font-family: Verdana;
display their default font. When using a multi-word font name, it is best practice }
to wrap them in quotes.
#page-title {
font-family: "Courier New";
}
Color Name Keywords
Color name keywords can be used to set color property values for elements in
CSS. h1 {
color: aqua;
}
li {
color: khaki;
}
Background Image
The background-image CSS property sets the background image of an
background-image: url("nyan-cat.gif");
element. An image URL should be provided in the syntax url("moon.jpg")
as the value of the property.