Merge PDF 888
Merge PDF 888
Colors
.transparent {
color: transparent;
}
CSS colors can be declared with the HSL color system .light-blue {
using hsl() syntax. This syntax contains three
background-color: hsl(200, 70%, 50%);
values: hue (the color value itself), saturation (intensity),
and lightness. }
Hue values range from 0 to 360 while saturation and
lightness values are represented as percentages.
CSS rgb() Colors
.green {
color: rgb(0, 255, 0);
}
li {
color: khaki;
}
Print Share
Cheatsheets / Learn CSS
The CSS z-index property specifies how far back //`element1` will overlap `element2`
or how far forward an element will appear on a web
.element1 {
page when it overlaps other elements.
The z-index property uses integer values, which position: absolute;
can be positive or negative values. The element with z-index: 1;
the highest z-index value will be at the
}
foreground, while the element with the lowest z-
index value will be at the back.
.element2 {
position: absolute;
z-index: -1;
}
The CSS float property determines how far left or /* The content will float to the left
how far right an element should float within its parent
side of the container. */
element. The value left floats an element to the left
side of its container and the value right floats an .left {
element to the right side of its container. For the float: left;
property float , the width of the container must
}
be specified or the element will assume the full width of
its containing element.
/* The content will float to the right
side of the container. */
.right {
float: right;
}
The CSS clear property
The CSS clear property specifies how an element /*This determines that no other elements
should behave when it bumps into another element
within the same containing element are
within the same containing element.The clear is
usually used in combination with elements having the allowed to float on the left side of this
CSS float property. This determines on which sides element.*/
floating elements are allowed to float.
.element {
clear: left;
}
Print Share
Cheatsheets / Learn CSS
The CSS box model is a box that wraps around an HTML .container {
element and controls the design and layout. The
box-sizing: border-box;
property box-sizing controls which aspect of
the box is determined by the height and width }
properties. The default value of this property is
content-box , which renders the actual size of
the element including the content box; but not the
paddings and borders. The value border-box , on
the other hand, renders the actual size of an element
including the content box, paddings, and borders.
CSS margin collapse occurs when the top and bottom /* The vertical margins will collapse to
margins of blocks are combined into a single margin
30 pixels
equal to the largest individual block margin.
Margin collapse only occurs with vertical margins, not instead of adding to 50 pixels. */
for horizontal margins. .block-one {
margin: 20px;
}
.block-two {
margin: 30px;
}
The CSS min-width and min-height /* Any element with class "column" will
properties can be used to set a minimum width and
be at most 200 pixels wide, despite the
minimum height of an element’s box. CSS max-
width and max-height properties can be used width property value of 500 pixels. */
to set maximum widths and heights for element boxes.
.column {
max-width: 200px;
width: 500px;
}
Print Share
Cheatsheets / Learn CSS
Typography
The CSS font-weight property declares how /* Sets the text as bolder. */
thick or thin should be the characters of a text.
p {
Numerical values can be used with this property to set
the thickness of the text. The numeric scale range of font-weight: 700;
this property is from 100 to 900 and accepts only }
multiples of 100. The default value is normal while
the default numerical value is 400 . Any value less
than 400 will have text appear lighter than the default
while any numerical value greater than the 400 will
appear bolder.
In the given example, all the <p> elements will appear
in a bolder font.
The CSS font-family property can have multiple /* Here `Arial` is the fallback font for
fonts declared in order of preference. In this case the
<p> tags */
fonts following the initial font are known as the fallback
fonts. p {
If the initial value of the property font-family font-family: "Helvetica", "Arial";
fails to load to the webpage, the fallback fonts will be
}
used.
Print Share
Cheatsheets / Learn CSS
Visual Rules
CSS declarations
/* CSS declarations */
text-align: center;
color: purple;
width: 100px;
Font Size
Background Color
!important Rule
Font Weight
Text Align
Background Image
Font Family
li {
color: khaki;
}
Print Share
Cheatsheets / Learn CSS
CSS classes can be reusable and applied to many /* Selects all elements with
elements. Class selectors are denoted with a period .
class="column" */
followed by the class name. CSS ID selectors should be
unique and used to style only a single element. ID .column {
selectors are denoted with a hash sign # followed by }
the id name.
Selector Chaining
CSS selectors can be chained so that rule sets apply /* Select h3 elements with the section-
only 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 {
h3.section-heading can be used. color: blue;
}
CSS type selectors are used to match all elements of a /* Selects all <p> tags */
given type or tag name. Unlike for HTML syntax, we do
p {
not include the angle brackets when using type
selectors for tag names. When using type selectors, }
elements are matched regardless of their nesting level
in the HTML.
Some HTML attributes can have multiple attribute <div class="value1 value2 value3"></div>
values. Multiple attribute values are separated by a
space between each attribute.
Selector Specificity
CSS ID selectors
The <link> element is used to link HTML <!-- How to link an external stylesheet
documents to external resources like CSS files. It
with href, rel, and type attributes -->
commonly uses:
href attribute to specify the URL to the
external resource <link
rel attribute to specify the relationship of
href="./path/to/stylesheet/style.css"
the linked document to the current document
type attribute to define the type of content rel="stylesheet" type="text/css">
being linked
Purpose of CSS
Inline Styles
CSS styles can be directly added to HTML elements by <h2 style="text-align: center;">Centered
using the style attribute in the element’s opening
text</h2>
tag. Each style declaration is ended with a semicolon.
Styles added in this manner are known as inline styles.
<p style="color: blue; font-size:
18px;">Blue, 18-point text</p>
Separating HTML code from CSS code
Print Share