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

الشريحة 1 من 19

مقدمة الفصل

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

  1. Add text shadows and text-stroke effects.
  2. Create rounded corners.
  3. Add shadows to elements.
  4. Create linear and radial gradients, and reflections.
  5. Create animations, transitions and transformations.
  6. Use multiple background images and image borders.
  7. Create a multicolumn layout.
  8. Use vendor prefixes.
تفاصيل المصدرالفصل 5 · الشريحة ⁦3⁩
المصدر
الفصل 5 · الشريحة ⁦3⁩

Text shadowsظل النص

The CSS3 text-shadow property adds a shadow effect to any text. It has four values:

  1. Horizontal offset

    Pixels to the left or right of the text. Negative → left, positive → right.

  2. Vertical offset

    Pixels up or down. Negative → up, positive → down.

  3. Blur radius

    0px = sharp edge (no blur); the greater the value, the more blurred the edges.

  4. Color

    The color of the text-shadow.

من الشرائح

  • h1 { text-shadow: -4px 4px 6px dimgrey; font-size: 400%; }
تفاصيل المصدرالفصل 5 · الشرائح ⁦4–5⁩
المصدر
الفصل 5 · الشرائح ⁦4–5⁩

سؤال سريع

Text shadows

Given text-shadow: 6px -3px 0px gray; where does the shadow appear, and what is its edge like?

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

Rounded corners and box shadowsالزوايا المستديرة وظل الصندوق

border-radius
Adds rounded corners to an element. Any value greater than half of the shortest side length produces a completely round end. Each corner can be set separately (border-top-left-radius, border-top-right-radius, border-bottom-left-radius, border-bottom-right-radius).
box-shadow
Shadows any block-level element: horizontal offset (positive → right), vertical offset (positive → down), blur radius (0px = sharp edge), color.

من الشرائح

  • border-radius: 15px;
  • box-shadow: 25px 25px 50px dimgrey;
تفاصيل المصدرالفصل 5 · الشرائح ⁦6, 9⁩
المصدر
الفصل 5 · الشرائح ⁦6, 9⁩

سؤال سريع

Rounded corners and box shadows

A button is 120px wide and 40px high. Which border-radius makes its left and right ends completely round?

تفاصيل المصدرالفصل 5 · الشريحة ⁦6⁩
المصدر
الفصل 5 · الشريحة ⁦6⁩

Linear gradients and vendor prefixesالتدرج الخطي والبادئات

Linear gradient
A type of image that gradually transitions from one color to the next horizontally, vertically or diagonally. The points where colors change are color-stops (pixels or percentages along the gradient line). Gradients can be used in any property that accepts an image.
Vendor prefixes
Used for properties that are still being finalized in the CSS specification but have already been implemented in various browsers.

من الشرائح

  • background: -webkit-gradient(linear, left top, right bottom, …);
  • background: -moz-linear-gradient(top left, white 15%, plum 50%, purple 75%);
  • background: linear-gradient(45deg, white 15%, plum 50%, purple 75%);
تفاصيل المصدرالفصل 5 · الشرائح ⁦12, 13, 20⁩
المصدر
الفصل 5 · الشرائح ⁦12, 13, 20⁩

سؤال سريع

Linear gradients and vendor prefixes

Why might a style sheet contain -webkit-…, -moz-… and a plain version of the same gradient rule?

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

Radial gradientsالتدرج الشعاعي

Radial gradient
Similar to a linear gradient, but the color changes gradually from an inner point (the start) to an outer circle (the end).

The three values in Fig. 5.6القيم الثلاث في المثال

  1. 1

    Position of the start — center (other values: top, bottom, left, right).

  2. 2

    Start color — yellow.

  3. 3

    End color — red.

من الشرائح

  • background: radial-gradient(center, yellow, red);
تفاصيل المصدرالفصل 5 · الشرائح ⁦21–22⁩
المصدر
الفصل 5 · الشرائح ⁦21–22⁩

سؤال سريع

Radial gradients, text stroke and reflections

A badge must be white in its middle, fading out to blue in a circle around it. Which CSS3 feature fits best?

تفاصيل المصدرالفصل 5 · الشريحة ⁦21⁩
المصدر
الفصل 5 · الشريحة ⁦21⁩

(Optional, WebKit only) Text stroke and reflectionsحد النص والانعكاس

Radial gradients, text stroke and reflections

-webkit-text-stroke
A nonstandard WebKit property that adds an outline (text stroke) around text: outline thickness (e.g., 2px) and stroke color.
-webkit-box-reflect
Adds a reflection of an image: first value direction (above, below, left, right), second value offset (space between image and reflection), optionally a gradient.
تفاصيل المصدرالفصل 5 · الشرائح ⁦24, 29⁩
المصدر
الفصل 5 · الشرائح ⁦24, 29⁩
ملاحظات حول المصدر (1)
  • هاتان الخاصيتان معلَّمتان في الشرائح «اختياري: WebKit فقط».

Multiple backgrounds and image bordersالخلفيات المتعددة وحدود الصور

Multiple background images and image borders

  • CSS3 allows multiple background images; the comma-separated background-position values match the order of the images in background-image.
  • background-origin places each image using the box model (e.g., border-box, content-box).
border-image
Uses images to place a border around any block-level element. border-image-slice divides the image into nine regions: four corners, four sides and a middle.

Stretched border

  • Sides stretched (distorted) to fit
  • Corners unchanged

Repeated border

  • border-image-repeat: repeat
  • Tiles repeated, partial tiles fill the excess space
تفاصيل المصدرالفصل 5 · الشرائح ⁦26, 32, 35, 36, 37⁩
المصدر
الفصل 5 · الشرائح ⁦26, 32, 35, 36, 37⁩

The animation propertyخاصية animation

Animation and @keyframes

Shorthand orderترتيب القيم

  1. animation-name

    The name of the animation.

  2. animation-timing-function

    How the animation progresses in one cycle.

  3. animation-duration

    Time (s or ms) for one iteration.

  4. animation-delay

    Time after the page loads before it begins.

  5. animation-iteration-count

    Number of runs; infinite repeats continuously.

  6. animation-direction

    alternate = alternating directions; default normal.

تفاصيل المصدرالفصل 5 · الشرائح ⁦42–45⁩
المصدر
الفصل 5 · الشرائح ⁦42–45⁩

Timing functions and @keyframesدوال التوقيت و keyframes

Animation and @keyframes

animation-timing-functionدالة التوقيتBehaviour (slide 43)السلوك
linearSame speed from start to finish
ease (default)Starts slowly, increases speed, then ends slowly
ease-inStarts slowly, then speeds up
ease-outStarts faster, then slows down
ease-in-outStarts and ends slowly
cubic-bezierCustom timing with four values between 0 and 1, e.g. cubic-bezier(1,0,0,1)
@keyframes
Defines the properties that change during the animation, the values they change to, and when they change. It is followed by the animation's name; its selectors (e.g., 0%, 25%, 50%, 75%, 100%) are points in time.
تفاصيل المصدرالفصل 5 · الشرائح ⁦43, 46⁩
المصدر
الفصل 5 · الشرائح ⁦43, 46⁩

سؤال سريع

Animation and @keyframes

animation: pulse ease-in 3s 2s infinite alternate; Which reading matches the order of the animation shorthand?

تفاصيل المصدرالفصل 5 · الشرائح ⁦43–44⁩
المصدر
الفصل 5 · الشرائح ⁦43–44⁩

Transitions and transformationsالانتقالات والتحويلات

Transitionالانتقال

  • Changes an element's style over a specified duration
  • Specifies only the starting and ending values

Animation (keyframes)الحركة

  • Keyframes control intermediate states throughout the duration
transition
For each changing property, its duration, e.g. transition: transform 4s, opacity 2s;
rotate
Receives degrees; negative values rotate left.
scale
1 = original size; > 1 increases, < 1 decreases.
skewX / skewY
Slant block-level elements horizontally / vertically.
  • :hover formerly worked only for anchor elements but now works with any element.
تفاصيل المصدرالفصل 5 · الشرائح ⁦47, 48, 51, 52⁩
المصدر
الفصل 5 · الشرائح ⁦47, 48, 51, 52⁩

سؤال سريع

Transitions and transformations

A designer needs an effect that passes through several intermediate positions (up, left, down, right) during its run. Should a transition or an animation be used?

تفاصيل المصدرالفصل 5 · الشريحة ⁦47⁩
المصدر
الفصل 5 · الشريحة ⁦47⁩

Multicolumn layoutالأعمدة المتعددة

column-count
Number of columns (Fig. 5.17 uses 3).
column-gap
The spacing between columns (30px in the example).
column-rule
Adds a line between each column.
  • Resizing the browser window changes the width of the columns to fit the layout.
تفاصيل المصدرالفصل 5 · الشريحة ⁦59⁩
المصدر
الفصل 5 · الشريحة ⁦59⁩

سؤال سريع

Multicolumn layout

Which property adds a line between the columns of a multicolumn layout?

تفاصيل المصدرالفصل 5 · الشريحة ⁦59⁩
المصدر
الفصل 5 · الشريحة ⁦59⁩

الخلاصة

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

خريطة الفصل

    1. 1مقدمة الفصل
  1. Text shadowsظل النص

    1. 2Text shadowsظل النص
    2. 3سؤال سريع: ظل النص
  2. Rounded corners and box shadowsالزوايا المستديرة وظل الصندوق

    1. 4Rounded corners and box shadowsالزوايا المستديرة وظل الصندوق
    2. 5سؤال سريع: الزوايا
  3. Linear gradients and vendor prefixesالتدرجات الخطية والبادئات

    1. 6Linear gradients and vendor prefixesالتدرج الخطي والبادئات
    2. 7سؤال سريع: البادئات
  4. Radial gradients, text stroke and reflectionsالتدرج الشعاعي وحدود النص والانعكاس

    1. 8Radial gradientsالتدرج الشعاعي
    2. 9سؤال سريع: التدرج الشعاعي
    3. 10(Optional, WebKit only) Text stroke and reflectionsحد النص والانعكاس
  5. Multiple background images and image bordersعدة صور خلفية وحدود الصور

    1. 11Multiple backgrounds and image bordersالخلفيات المتعددة وحدود الصور
  6. Animation and @keyframesالحركة و @keyframes

    1. 12The animation propertyخاصية animation
    2. 13Timing functions and @keyframesدوال التوقيت و keyframes
    3. 14سؤال سريع: الحركة
  7. Transitions and transformationsالانتقالات والتحويلات

    1. 15Transitions and transformationsالانتقالات والتحويلات
    2. 16سؤال سريع: الانتقال
  8. Multicolumn layoutالتخطيط متعدد الأعمدة

    1. 17Multicolumn layoutالأعمدة المتعددة
    2. 18سؤال سريع: الأعمدة
    1. 19الخلاصة