Common CSS Properties

Background Colors & Images

background-color

Sets the color of the background of the element. Background colors use a hexadecimal number, or you can use a set of standard color names, like red or blue.

To determine the hex codes for colors you can look them up in a program such as Photoshop or Illustrator. You can also use an online tool like this one.

background-image

Sets the background as an image. The image will repeat unless specifically noted not to. The image is found with a relative link. If the image is in a folder, the link in the CSS value should include that folder.

background-image

By default, background images repeat. You can edit this with the background-repeat property.

background-size

If you always want the background image to be large enough to fill the space and respond to the browser size, use the background-size property.

Fonts

font-family

Some folks don’t have the font you want to use on their system, so in most cases you use the font-family property to set multiple font choices listing in order of preference.

font-size

Sets the size of type. You can use different units of measurement, but pixels are most widely used.

font-weight

Sets the weight of the font from light to bold. You can define the weight with words:"normal", "bold", "lighter", etc. or with a number: "100", "200".."700".

font-style

Sets the style of a font to bold or italics.

text-decoration

Text decoration can put an underline, overline, or strike through on your text. This one is particularly useful when you want to remove an underline. To remove an underline, use "none" as the value.

color

Sets the color of type. Web colors use a hexadecimal number, or you can use a set of standard color names, like red or blue.

To determine the hex codes for colors you can look them up in a program such as Photoshop or Illustrator. You can also use an online tool like this one.

text-transform

Allows you to set the type to all caps.

text-align

Specifies the horizontal alignment of text. DO NOT CENTER YOUR TEXT unless you . Are you just trying to balance the page? How else can you solve the problem besides centering the text?

line-height

Adjusts the line height of text. You can define it with a number or percentage.

list-style

Sets the characters used in a list (bullet, square, none). Handy for removing bullets from elements.

Size & Space

width

Define the width of an element (such as an image). You can also set a max-width or a min-width. These are great for a responsive websites (you need the element to grow or shrink based on the device size).

height

Define the height of an element. USE THIS WITH CAUTION. Frequently defining the height of an element will break the design of your site. How else can you solve the problem?

display

Sets the box type of an element. Elements either act like a box (block) and stack on each other, or act like water and flow around each other (inline). This is handy for getting block elements like list elements to display side by side.

margin

If you think of elements as little boxes the margin is the space pushing out from the edge of the box to other elements. The margin can be set on individual sides (margin-right, margin- bottom, etc.) or all of the sides at the same time. To set the all of the sides, set the top, right, bottom, left in that order

padding

If you think of elements as little boxes the padding is the space pushing inward from the edge of the box into the content. The padding can be set on individual sides (padding-right, padding- bottom, etc.) or all of the sides at the same time. To set the all of the sides, set the top, right, bottom, left in that order.

Effects

border

Set the color, size and style of border around an element. You can set individual sides (border-right, border-left) or all of the sides at the same time. To set the all of the sides set the size, style and color in that order

Rotate

To rotate elements, use the transform property with the rotate value. See the syntax is the example below.

Round Corners

Round corners can be created with the "border-radius". The value can be set in percentage or pixels.

Round corners can applied to each individual corner by setting 4 values.

Circles

Circles can be created by setting the value of "border-radius" to 50%. Keep in mind your object must be square in order for your object to be a circle and not an oval.

Drop Shadow

Drop shadow can be added to text or boxes with a few lines of CSS. The value of drop shadow can define the size, spread, and color of the shadow.

box-shadow: h-offset v-offset blur spread color

The most effective way to create your shadow with code is to use a Shadow Generator like this one.

Centering Text & Images

Centering Content

To center content within the browser, you need to define the width of the content and then set the left and right margin to "auto".

Centering Images

Images are tricky to center because by default they are inline objects, meaning they secretly take up the full width of the section, despite how large or small the image is. To center the image, make sure to change the display to "block".

Link States

Links use pseudo-classes to demonstrate interactions. These include hover, visited, and active.

These pseudo-classes are created by using a colon after the selector name.

CSS Animation

Animation is a strategic component in web design used to indicate action, influence user behavior, and call attention. Using animation as hover states is both fun and effective... and fairly easy!

Troubleshooting CSS