Ways of Applying CSS to HTML

Applying CSS within the opening tag of a HTML element

Within the opening tag of an HTML element, the element can be stylized using a style property. Use by applying style = 'property1: value1; property2: value2' within the opening tag.

Inserting an Internal Stylesheet into the head of an HTML document.

CSS can be placed directly inside the head of the head element of an html page. Place CSS code within <style> tags in the same way you would in a seperate file.

CSS - Linking and External Stylesheet to an HTML file.

In the <head> tag of an HTML file, CSS files are linked and thus function to apply all of the styling to the page. To link a CSS file to html, a <link> tag must be applied with attributes of "href" set to the css file and the "rel" attribute set to "stylesheet".

CSS Overview

Rather than applying a style to different elements directly, CSS allows you to use a different syntax to apply format categories of html elements. In general, CSS application looks like:

div {

color: green;

}

In this example, div is a selector, everything between the {} is a declaration block, color is a property, green is a value, and the paired two of them is a declaration.

Suggestions and Practices

Some developers will choose to start their CSS file with a reset of default margin and padding values. This is done by using:

* {

margin:0

padding:0

}

CSS Selectors

A selector is how you write CSS in a manner that applies it to select HTML elements.

Selector Specificity Preferences

When multiple selectors target the same element with conflicting attributes, the most specific selector overrides the less specific selector. This functions as follows:

id > Descendant combinator w/class > class > type

Style Element Attributes and Values to Set Using CSS

font-family - allows for the selection of a text font. Example: font-family: Arial;

font-size - allows setting of a font size. Example: font-size: 12px;

fort-weight - enables bolding or setting the weight of text. Example: font-weight: bold;

text-transform - use to modify text in stylistic manners

color - use to change text to a specific color.

background-color - use to change the background color of an element.

background-image - can set an image as the background of an object. Example: background-image: url('folder/image2.jpg')

border - places border around element. Specify inside the size style color. Example: border: 2px dashed red

opacity - makes an element transparent or opaque (impacts container). Good to use for captions overlaying an image. Example: opacity: 0.75 (somewhat transparent)

text-align - aligns text to the left, center, or right of its container.

The Box Model

A picture of the CSS Box Model

Dimensional Shorthand

Rather than setting each settings of padding-top, bottom, etc... each padding/margin can be assigned multiple values seperated by spaces to indicate these values. This works as follows:

HTML Flow - CSS Attributes

HTML by default will position elements from left to right and from top to bottom. These attributes manipulate these positionings.

CSS Color Styling

Color can be expressed in CSS using several different schemes.

Methods of Applying Colors

CSS Font Applications

Several high level considerations apply to setting fonts on webpages. A font is selected by applying a font-family attribute to a text element on a html page. Example: font-family: Arial.

The following specific attributes can be modified to further customize font on the page.

Using Web Fonts

Links can be placed in the header of an HTML document to enable the use of webfonts using services like Google WebFonts

See this text using Google Bebas Neue font.

When visiting webpages, it is helpful to design specific text in a manner that helps the user better navigate information. Several elements are uniquely styled with this in mind.

To be Continued on Pg.3 of Links and Buttons...