• No results found

css_.pptx

N/A
N/A
Protected

Academic year: 2020

Share "css_.pptx"

Copied!
55
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

Table of Contents

What is CSS?

Styling with Cascading Style sheets (CSS)

Selectors and style definitions

Linking HTML and CSS

(3)

CSS: A New Philosophy

Separate content from presentation!

Title

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse at pede ut purus malesuada dictum. Donec vitae neque non magna aliquam dictum.

(4)

The Resulting Page

Title

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse at pede ut purus malesuada dictum. Donec vitae neque non magna aliquam dictum.

Vestibulum et odio et ipsum

accumsan accumsan. Morbi at arcu vel elit ultricies porta. Proin

(5)
(6)

CSS Introduction

Cascading Style Sheets (CSS)

Used to describe the presentation of documentsDefine sizes, spacing, fonts, colors, layout, etc.Improve content accessibility

Improve flexibility

(7)

CSS Introduction

CSS stands for Cascading Style Sheets

Styles define how to display HTML elements Styles are normally stored in Style Sheets

Styles were added to HTML 4.0 to solve a

problem

External Style Sheets can save you a lot of work External Style Sheets are stored in CSS files

(8)

Cont…

CSS can be applied to any XML document

(9)

Multiple Styles Will Cascade into One

Style sheets allow style information to be specified in

(10)

Cascading Order

Generally speaking we can say that all the styles

will cascade into a new virtual style sheet by

ʺ

ʺ

ʺ

ʺ

the following rules, where number four has the

highest priority:

Browser default

External style sheet

(11)

CSS Syntex

The CSS syntax is made up of three parts: a selector, a property and a value:

Selector Property Value

Ex : ‐ selector { property : value } body { color: black }

(12)

Style Sheets Syntax

More then one property, Separate each

property with semicolon

(13)

Grouping

Selectors are separated by commas

Declarations are separated by semicolons

Properties and values are separated by colons

(14)

Class selector

p.right {text-align: right} p.center {text-align: center}

HTML Code

<p class="right">

This paragraph will be right-aligned.

</p><p class="center">

(15)

Id Selector

You can also define styles for HTML elements

with the id selector. The id selector is defined as

a #.

(16)

CSS Comments

Comments are used to explain your code, and

may help you when you edit the source code

at a later date. A comment will be ignored by

browsers. A CSS comment begins with /* ,

ʺ ʺ

and ends with */ , like this:

ʺ ʺ

(17)

Selectors determine which element the rule

applies to:

All elements of specific type (tag)

Those that match a specific attribute (id, class)

Elements may be matched depending on how they

are nested in the document tree (HTML)

Examples:

.header a { color: green }

(18)

Cont…

Three primary kinds of selectors are :

By tag (type selector):

By element id:

By element class name (only for HTML): Example

Selectors can be combined with commas:

This will match <h1> tags, elements with class link, and element with id top-link

h1 { font-family: verdana,sans-serif; }

#element_id { color: #ff0000; }

.myClass {border: 1px solid red}

(19)

Cont…

Pseudo-classes define state

:hover, :visited, :active , :lang

Pseudo-elements define element "parts" or are

used to generate content

:first-line , :before, :after

a:hover { color: red; }

p:first-line { text-transform: uppercase; } .title:before { content: "»"; }

(20)

Cont…

Match relative to element placement:

This will match all

<a>

tags that are inside of

<p>

*

– universal selector (avoid or use with care!):

Universal selectors are used to select any element. The above rule will color all HTML elements on a page blue - regardless of their position in the document tree.

Click Here

+

selector – used to match “next sibling”:

This will match all siblings with class name

link

that appear immediately after

<img>

tag

p a {text-decoration: underline}

* {color: blue}

(21)

Cont…

> selector – matches direct child nodes:

This will match all elements with class error, direct children of <p> tag

[ ] – matches tag attributes by regular expression:

This will match all <img> tags with alt attribute containing the word logo

.class1.class2 (no space) - matches elements

with both (all) classes applied at the same time

p > .error {font-size: 8px}

(22)

Values in the CSS Rules

Colors are set in RGB format (decimal or hex):

Example: #a0a6aa = rgb(160, 166, 170)Predefined color aliases exist: black, blue, etc.

Numeric values are specified in:

Pixels, ems, e.g. 12px , 1.4em

Points, inches, centimeters, millimeters

E.g. 10pt , 1in, 1cm, 1mm

Percentages, e.g. 50%

(23)

Default Browser Styles

Browsers have default CSS styles

Used when there is no CSS information or any other

style information in the document

Caution: default styles differ in browsers

E.g. margins, padding and font sizes differ most

(24)

Linking HTML and CSS

HTML (content) and CSS (presentation) can be linked

in three ways:

Inline: the CSS rules in the style attribute

No selectors are needed

Embedded: inside the <head> in a <style> tagExternal: CSS rules in separate file (best)

Usually a file with .css extension

Linked via <link rel="stylesheet" href=…> tag or @import directive in embedded CSS block

Using external files is highly recommended

Simplifies the HTML document

(25)

Cont…

1. Inline Styles: Example

2. Embedded Styles: Example

Embedded in the HTML in the <style> tag:

The <style> tag is placed in the <head> section of the

document

type attribute specifies the MIME type

MIME describes the format of the content

Other MIME types include text/html, image/gif,

text/javascript …

(26)

External Style Sheet

An external style sheet is ideal when the style is

applied to many pages.

<head>

<link rel="stylesheet" type="text/css" href="mystyle.css" />

</head>

hr {color: sienna} p {margin-left: 20px}

body {background-image: url("back40.gif")}

(27)

Internal Style Sheet

An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section by using the <style> tag, like this:

<head>

<style type="text/css"> hr {color: sienna}

p {margin-left: 20px}

body {background-image: url("images/back40.gif")} </style>

(28)

Inline Styles

An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly, such as when a style is to be applied to a single occurrence of an element.

To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:

<p style="color: sienna; margin-left: 20px"> This is a paragraph

(29)

Cont…

3. External CSS Styles

Separate pages can all use a shared style sheet

Only modify a single file to change the styles across

your entire Web site

link

tag (with a

rel

attribute) :

Example_1

Specifies a relationship between current document

and another document

link elements should be in the <head>

(30)

Cont…

@import :

Example_2

,

Example_3

Another way to link external CSS filesExample:

Ancient browsers do not recognize @import

<style type="text/css">

@import url("styles.css"); /* same as */

(31)

CSS - Background

• You can set the following background properties of an element −

The background-color property is used to set the background color of

an element.

The background-image property is used to set the background image of

an element.

The background-repeat property is used to control the repetition of an

small image in the background.

1. Use no repeat value for no repetition.

2. Use repeat-y to repeat background image vertically 3. Use repeat-x to repeat background image horizontally

The background-position property is used to control the position of an

image in the background.

The background-attachment property is used to control the scrolling of

(32)
(33)
(34)

Background-image

(35)
(36)
(37)
(38)

CSS TEXT

The CSS text properties allow you to control the appearance

of text.

It is possible to change the color of a text, increase or decreas

e the space between characters in a text, align a

(39)
(40)
(41)

CSS font

(42)
(43)
(44)
(45)

CSS border

The CSS border properties allow you to specify

the style and color of an element's border.

In HTML we use tables to create borders around

a text, but with the CSS border

(46)
(47)
(48)

Border style

dotted - Defines a dotted border

dashed - Defines a dashed bordersolid - Defines a solid border

• double - Defines a double border

groove - Defines a 3D grooved border. The effect depends on the border-color

value

ridge - Defines a 3D ridged border. The effect depends on the border-color

value

inset - Defines a 3D inset border. The effect depends on the border-color valueoutset - Defines a 3D outset border. The effect depends on the border-color

value

none - Defines no border

(49)
(50)

CSS Margin

The CSS margin properties define the space

around elements. It is possible to use negative values to overlap content. The top, right,

bottom, and left margin can be

changed independently using separate properties.

A shorthand margin property can also be used to

(51)
(52)
(53)

CSS padding

The CSS padding properties define the

space between the element border and

the

element content.

Negative values are not allowed. The top,

(54)
(55)

References

Related documents

Northern Lake Garda by private boat (Riva, Limone &amp; Malcesine) (three quarter day) Southern Lake Garda (Lazise, Sirmione &amp; Salò) including wine tasting (full day)

&gt; Appointment of senior executive resource in Australia supports positive outlook &gt; Focused on continued portfolio improvement, proactive tenant engagement &gt;

W3C standard: Document Object Model (DOM) for HTML and XML) &lt;html&gt; &lt;head&gt; &lt;title&gt; &lt;body&gt; … … &lt;/body&gt; &lt;/html&gt; HTML Parser document form input

HTML tag &lt;img&gt; can also be used if you want to include the image inside text provided by other fields/subfields or the PFT. The &lt;img/&gt; element allows you to insert an

At the end of the page is a corresponding &lt;/HTML&gt; closing tag (the slash means it closes the HTML element).. • This idea of opening and closing tags is key to

[r]

between the active duty locations model and the MCRC locations model, which serves as an indication that passive measures of recruiting (i.e., presence of active duty personnel

To better enable DOD to plan for funding EOD mission requirements and enhance future use of EOD forces in joint combat operations, GAO recommends that DOD direct (1) the