• No results found

CSCI 1150 Cascading Style Sheets

N/A
N/A
Protected

Academic year: 2022

Share "CSCI 1150 Cascading Style Sheets"

Copied!
38
0
0

Loading.... (view fulltext now)

Full text

(1)

CSCI 1150 – Cascading Style Sheets

Xin Yang

March 12, 2016

(2)

What is CSS?

I CSS stands for Cascading Style Sheets.

I CSS defines how HTML elements are to be displayed.

I CSS saves a lot of work. It can control the layout of multiple web pages all at once.

(3)

CSS Syntax

A CSS rule set consists of a selector and a declaration block:

(4)

CSS Syntax

I The selector points to the HTML element you want to style.

I The declaration block contains one or more declarations separated by semicolons.

(5)

CSS Syntax

I Each declaration includes a CSS property name and a value, separated by a colon.

I A CSS declaration always ends with a semicolon, and declaration blocks are surrounded by curly braces.

(6)

CSS How To ...

When a browser reads a style sheet, it will format the HTML document according to the information in the style sheet.

There are three ways of inserting a style sheet:

I External style sheet.

I Internal style sheet.

I Inline style.

(7)

External Style Sheet

I With an external style sheet, you can change the look of an entire website by changing just one file!

I Each page must include a reference to the external style sheet file inside the <link>

element. The <link> element goes inside the

<head> section:

(8)

External Style Sheet

(9)

External Style Sheet

I An external style sheet can be written in any text editor.

I The file should not contain any html tags.

I The style sheet file must be saved with a .css extension.

(10)

External Style Sheet

I Here is how the ”mystyle.css” looks:

(11)

Internal Style Sheet

I An internal style sheet may be used if one single page has a unique style.

I Internal styles are defined within the <style>

element, inside the <head> section of an HTML page:

(12)

Internal Style Sheet

(13)

Inline style

I An inline style may be used to apply a unique style for a single element.

I To use inline styles, add the style attribute to the relevant tag.

I The style attribute can contain any CSS property.

(14)

Inline style

(15)

Cascading Order

I

What style will be used when there

is more than one style specified for

an HTML element?

(16)

Cascading Order

I Generally speaking we can say that all the styles will ”cascade” into a new ”virtual” style sheet by the following rules, where number one has the highest priority:

I 1. Inline style (inside an HTML element).

I 2. External and internal style sheets (in the head section)

I 3. Browser default

(17)

Cascading Order

I So, an inline style (inside a specific HTML element) has the highest priority, which means that it will override a style defined inside the

<head> tag, or in an external style sheet, or a browser default value.

(18)

CSS Colors

Colors in CSS are most often specified by:

I a valid color name - like ”red”.

I an RGB value - like ”rgb(255, 0, 0)”.

I a HEX value - like ”#ff0000”.

(19)

Color Names

Colors set by using color names:

HTML and CSS supports 140 standard color names.

(20)

RGB (Red, Green, Blue)

RGB color values can be specified using this formula: rgb(red, green, blue):

HTML Color Picker.

(21)

Hexadecimal Colors

RGB values can also be specified using hexadecimal color values in the form: #RRGGBB, where RR (red), GG (green) and BB (blue) are hexadecimal values between 00 and FF (same as decimal 0-255):

HTML Color Picker.

(22)

Text Colors

(23)

Text Alignment

I The text-align property is used to set the horizontal alignment of a text.

I A text can be left or right aligned, centered, or justified.

I The following example shows center aligned, and left and right aligned text:

(24)

Font Size

I The font-size property sets the size of the text.

(25)

Font Family

I The font-family property sets the font family of the text.

(26)

CSS Backgrounds

I The CSS background properties are used to define the background effects for elements.

I CSS background properties:

I background-color

I background-image

I background-repeat

I background-attachment

I background-position

(27)

Background Color

I The background-color property specifies the background color of an element.

I The background color of a page is set like this:

(28)

Background Color

I The background-color property specifies the background color of an element.

I In the example below, the <h1>, <p>, and

<div> elements have different background colors:

(29)

Background Image

I The background-image property specifies an image to use as the background of an element.

I By default, the image is repeated so it covers the entire element.

I The background image for a page can be set like this:

(30)

Background Image

(31)

Background Image - Repeat Horizontally

I By default, the background-image property repeats an image both horizontally and vertically.

I To repeat an image horizontally set background-repeat: repeat-x:

(32)

Background Image - Repeat Vertically

I By default, the background-image property repeats an image both horizontally and vertically.

I To repeat an image vertically set background-repeat: repeat-y:

(33)

Background Image - No Repeat

I Showing the background image only once is also specified by the background-repeat property:

(34)

Background Image - Set Position

I The position of the image is specified by the background-position property:

(35)

Background Image - Fixed Position

I To specify that the background image should be fixed (will not scroll with the rest of the page), use the background-attachment property:

(36)

Background Image - Fixed Center

(37)

CSS Comment

I Comments are used to explain the code, and may help when you edit the source code at a later date.

I Comments are ignored by browsers.

I A CSS comment starts with /* and ends with

*/. Comments can also span multiple lines:

(38)

References

1 http://www.w3schools.com

References

Related documents

We consider a stochastic risk reserve process whose risk exposure can be controlled dy- namically by applying proportional reinsurance and by issuing CAT Bonds.. The CAT Bond

Key words : gendered international political economy, social reproduction, markets, national accounting, domestic economy, state, women's work.. Address for correspondence:

Blockley isolates harboured a macrolide inactivation gene cluster mphA- 37 mrx-mphr(A) within a novel Salmonella Azithromycin Resistance Genomic Island (SARGI), the full.. 38

Please register me for the Training Course in Hospital Epidemiology November 6-9, 2005 - Hotel Novotel, Beaune, France.

1 shows the results of the calculated corrosion rate obtained from the weight-loss of the specimens immersed in 0.5 M HCl using separately two magnesium anodes of different sizes

following formula for the optimal level of insurance:.. The optimal level of benefits thus involves a tradeoff between the social cost of moral hazard, which depends on !

Bahan makanan ikan Sapu-sapu (P. pardalis) yang terdapat di Sungai Air Hitam dan Sungai Siak Desa Tualang diduga berbeda, karena bahan-bahan dari luar yang masuk

In more recent years, as train operating speeds increase, the dynamic effects caused by trains passing over bridges, the running safety and riding comfort of the train have