Introduction to Cascading Style Sheets (CSS): Part 1مقدمة في أوراق الأنماط المتتالية (CSS): الجزء الأول

الشريحة 1 من 21

مقدمة الفصل

ماذا ستتعلم في هذا الفصل

  1. Control a website's appearance with style sheets.
  2. Use a style sheet to give all the pages of a website the same look and feel.
  3. Use the class attribute to apply styles.
  4. Specify the precise font, size, color and other properties of displayed text.
  5. Specify element backgrounds and colors.
  6. Understand the box model and how to control margins, borders and padding.
  7. Use style sheets to separate presentation from content.
تفاصيل المصدرالفصل 4 · الشريحة ⁦2⁩
المصدر
الفصل 4 · الشريحة ⁦2⁩

CSS3 and inline stylesCSS3 والأنماط المضمنة

Cascading Style Sheets 3 (CSS3)
Used to specify the presentation of elements separately from the structure of the document.
Inline style
Declares an individual element's format using the HTML5 attribute style.
  • Each CSS property is followed by a colon and the value.
  • Multiple property declarations are separated by a semicolon.

من الشرائح

  • <p style = "font-size: 20pt; color: deepskyblue;">
تفاصيل المصدرالفصل 4 · الشرائح ⁦3–4⁩
المصدر
الفصل 4 · الشرائح ⁦3–4⁩

Embedded style sheetsالأنماط المدمجة

Embedded style sheet
Embeds a CSS3 document in an HTML5 document's head section, inside a style element. Its selectors apply styles throughout the entire document.
  • The style element's type attribute gives the MIME type; style sheets use text/css.
  • Each rule body is enclosed in curly braces ({ and }).
Fig. 4.4 — A few common MIME types
MIME typeنوع MIMEDescriptionالوصف
text/cssCSS documents
image/pngPNG images
text/javascriptJavaScript markup
text/plainPlain text
image/jpegJPEG image
text/htmlHTML markup
تفاصيل المصدرالفصل 4 · الشرائح ⁦8, 9, 11, 12, 13⁩
المصدر
الفصل 4 · الشرائح ⁦8, 9, 11, 12, 13⁩

Font properties and style classesخصائص الخط والأصناف

Embedded style sheets, selectors and style classes

font-weight
The "boldness" of text: bold, normal (default), bolder, lighter, or 100–900 (normal = 400, bold = 700).
Style class
Preceded by a period (.); can be applied to any element, e.g. .special { color: purple; }. id selectors have the form #elementId.
font-family
The name of the font. Generic font families specify a type of font in case a browser does not support a specific font.
font-size
A point size or an absolute value (xx-small … xx-large). Relative values (smaller, larger) are preferred because the author does not know each client's display.
تفاصيل المصدرالفصل 4 · الشرائح ⁦14, 15, 16, 18⁩
المصدر
الفصل 4 · الشرائح ⁦14, 15, 16, 18⁩

سؤال سريع

Embedded style sheets, selectors and style classes

An embedded style sheet contains .note { color: green; }. Which element will be green?

تفاصيل المصدرالفصل 4 · الشريحة ⁦15⁩
المصدر
الفصل 4 · الشريحة ⁦15⁩

Conflicting stylesتعارض الأنماط

Styles may be defined by a user, an author or a user agent. Styles cascade (flow together) — hence "Cascading Style Sheets".

Precedence (slide 20)الأولوية

  1. Highest

    Author styles — take precedence over user styles.

  2. Then

    User styles — take precedence over user-agent styles.

  3. Lowest

    User-agent styles.

  • Most styles defined for parent elements are inherited by child (nested) elements.
  • Properties defined for child and descendant elements have higher specificity; conflicts are resolved in favor of higher specificity, so the child's styles take precedence.
تفاصيل المصدرالفصل 4 · الشرائح ⁦19, 20, 22⁩
المصدر
الفصل 4 · الشرائح ⁦19, 20, 22⁩

سؤال سريع

Conflicting styles: cascade, inheritance and specificity

A browser's default style, a reader's own style and the site author's style all set the size of paragraph text. Whose style takes precedence?

تفاصيل المصدرالفصل 4 · الشريحة ⁦20⁩
المصدر
الفصل 4 · الشريحة ⁦20⁩

text-decoration and hovertext-decoration و hover

Conflicting styles: cascade, inheritance and specificity

text-decoration values

  • underline
  • overline
  • line-through
  • blink
Pseudoclasses
Give you access to content that's not declared in the document. The hover pseudoclass is activated when the user moves the mouse cursor over an element.
تفاصيل المصدرالفصل 4 · الشرائح ⁦21, 25⁩
المصدر
الفصل 4 · الشرائح ⁦21, 25⁩

Length measurementsوحدات القياس

Relative (slide 26)نسبيةAbsolute (slide 26)مطلقة
px — pixels; size varies with screen resolutionin — inches
em — usually the height of a font's uppercase Mcm — centimeters
ex — usually the height of a font's lowercase xmm — millimeters
% — percentage of the font's default sizept — points (1 pt = 1/72 in)
pc — picas (1 pc = 12 pt)
تفاصيل المصدرالفصل 4 · الشريحة ⁦26⁩
المصدر
الفصل 4 · الشريحة ⁦26⁩

Linking external style sheetsالأنماط الخارجية

External style sheet
A separate document that contains only CSS rules. Separate pages can all use the same styles; modifying a single file changes styles across the website — sometimes known as skinning.
rel
The relationship between the two documents (the linked document is a stylesheet).
type
The MIME type of the related document.
href
The URL of the document containing the style sheet.

من الشرائح

  • <link rel = "stylesheet" type = "text/css" href = "styles.css">
  • CSS comments start with /* and end with */ and can be used in any type of CSS code.
تفاصيل المصدرالفصل 4 · الشرائح ⁦27, 28, 30, 31⁩
المصدر
الفصل 4 · الشرائح ⁦27, 28, 30, 31⁩

سؤال سريع

Linking external style sheets

A university wants all 200 of its pages to change color scheme by editing one file. Which approach and markup fit?

تفاصيل المصدرالفصل 4 · الشرائح ⁦27, 30⁩
المصدر
الفصل 4 · الشرائح ⁦27, 30⁩

Backgroundsالخلفيات

background-image
The URL of the image: url(fileLocation).
background-position
top, bottom, center, left, right individually or combined, or lengths.
background-repeat
no-repeat (one copy), repeat (default: vertical and horizontal), repeat-x (horizontal), repeat-y (vertical).
background-attachment: fixed
Fixes the image in the position set by background-position; scrolling will not move it. The default, scroll, moves the image as the user scrolls.
text-indent
Indents the first line of text by the specified amount.

من الشرائح

  • body { background-image: url(logo.png); background-position: bottom right; background-repeat: no-repeat; background-attachment: fixed; background-color: lightgrey; }
تفاصيل المصدرالفصل 4 · الشرائح ⁦33, 34, 36, 37, 38, 39⁩
المصدر
الفصل 4 · الشرائح ⁦33, 34, 36, 37, 38, 39⁩

سؤال سريع

Backgrounds and text formatting

Which rule shows logo.png exactly once in the bottom-left corner and keeps it there while the page scrolls?

تفاصيل المصدرالفصل 4 · الشرائح ⁦36–38⁩
المصدر
الفصل 4 · الشرائح ⁦36–38⁩

Element dimensionsأبعاد العناصر

  • width and height set an element's dimensions; values can be relative or absolute.
  • text-align: center, left or right.
  • If content exceeds the set boundaries, overflow: scroll adds scroll bars.
تفاصيل المصدرالفصل 4 · الشرائح ⁦43–44⁩
المصدر
الفصل 4 · الشرائح ⁦43–44⁩

The box modelنموذج الصندوق

Box model, borders and floating

From the inside outمن الداخل إلى الخارج

  1. Content

    The element's content.

  2. Padding

    Distance between the content and the inside of the border.

  3. Border

    Controlled by border-width, border-color and border-style.

  4. Margin

    Space between the outside of the border and all other content.

  • Each side can be set separately: padding-top / -right / -left / -bottom and margin-top / -right / -left / -bottom.
  • border-style options: none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset.
  • Floating moves an element to one side of the screen; other content flows around it.
تفاصيل المصدرالفصل 4 · الشرائح ⁦45, 46, 51, 55⁩
المصدر
الفصل 4 · الشرائح ⁦45, 46, 51, 55⁩

سؤال سريع

Box model, borders and floating

A designer wants more space between a paragraph's text and its own border, without moving the border away from other elements. Which property should change?

تفاصيل المصدرالفصل 4 · الشرائح ⁦45, 55⁩
المصدر
الفصل 4 · الشرائح ⁦45, 55⁩

Media types and media queriesالوسائط والاستعلامات

Media types, media queries and drop-down menus

CSS media types
Decide what a page should look like depending on the kind of media used to display it. The most common is screen.
  • @media all { … } — styles for all media types.
  • @media print { … } — styles for a single media type such as print.

Media features (media queries)

  • width
  • height
  • device-width
  • device-height
  • orientation
  • aspect-ratio
  • device-aspect-ratio
تفاصيل المصدرالفصل 4 · الشرائح ⁦56, 57, 61⁩
المصدر
الفصل 4 · الشرائح ⁦56, 57, 61⁩

Drop-down menusالقوائم المنسدلة

:hover
Applies styles to an element when the mouse cursor is over it.
display
Displays an element as block, inline, or not at all (none).

من الشرائح

  • nav ul { display: none; … }
  • nav:hover ul { display: block; }
تفاصيل المصدرالفصل 4 · الشرائح ⁦62–63⁩
المصدر
الفصل 4 · الشرائح ⁦62–63⁩

سؤال سريع

Media types, media queries and drop-down menus

A nav contains a ul that should act as a drop-down menu. Which rules make the list hidden until the mouse is over the nav?

تفاصيل المصدرالفصل 4 · الشرائح ⁦62–63⁩
المصدر
الفصل 4 · الشرائح ⁦62–63⁩

(Optional) User style sheetsأوراق أنماط المستخدم

  • Users can define their own user style sheets based on their preferences; they are not linked to a document but set in the browser's options.
  • Absolute font sizes override user style sheets; relative font sizes yield to a user-defined style.
تفاصيل المصدرالفصل 4 · الشرائح ⁦65, 66, 73⁩
المصدر
الفصل 4 · الشرائح ⁦65, 66, 73⁩
ملاحظات حول المصدر (1)
  • هذا القسم معلَّم في الشرائح بأنه اختياري.

الخلاصة

تفاصيل المصدر
المصدر
الفصل 4

خريطة الفصل

    1. 1مقدمة الفصل
    1. 2CSS3 and inline stylesCSS3 والأنماط المضمنة
  1. Embedded style sheets, selectors and style classesأوراق الأنماط المدمجة والمحددات والأصناف

    1. 3Embedded style sheetsالأنماط المدمجة
    2. 4Font properties and style classesخصائص الخط والأصناف
    3. 5سؤال سريع: الأصناف
  2. Conflicting styles: cascade, inheritance and specificityتعارض الأنماط

    1. 6Conflicting stylesتعارض الأنماط
    2. 7سؤال سريع: الأولوية
    3. 8text-decoration and hovertext-decoration و hover
    1. 9Length measurementsوحدات القياس
  3. Linking external style sheetsربط أوراق الأنماط الخارجية

    1. 10Linking external style sheetsالأنماط الخارجية
    2. 11سؤال سريع: الأنماط الخارجية
  4. Backgrounds and text formattingالخلفيات وتنسيق النص

    1. 12Backgroundsالخلفيات
    2. 13سؤال سريع: الخلفيات
  5. Element dimensions and overflowأبعاد العناصر والفائض

    1. 14Element dimensionsأبعاد العناصر
  6. Box model, borders and floatingنموذج الصندوق والحدود والطفو

    1. 15The box modelنموذج الصندوق
    2. 16سؤال سريع: الحشو
  7. Media types, media queries and drop-down menusأنواع الوسائط والاستعلامات والقوائم المنسدلة

    1. 17Media types and media queriesالوسائط والاستعلامات
    2. 18Drop-down menusالقوائم المنسدلة
    3. 19سؤال سريع: القائمة المنسدلة
    1. 20(Optional) User style sheetsأوراق أنماط المستخدم
    1. 21الخلاصة