1. יחידות מידה ב-CSS
| יחידה | משמעות | דוגמה |
|---|---|---|
| px | פיקסלים | 200px |
| % | אחוזים מההורה | 50% |
| vw | אחוז מרוחב חלון הדפדפן | 100vw |
| vh | אחוז מגובה חלון הדפדפן | 100vh |
| svh | גובה חלון קטן | 100svh |
| dvh | גובה חלון דינמי | 100dvh |
| em | יחס לגודל הגופן של האלמנט | 2em |
| rem | יחס לגודל הגופן של HTML | 2rem |
| ch | רוחב תו 0 | 30ch |
| ex | גובה אות x | 2ex |
| vmin | אחוז מהצד הקטן של החלון | 50vmin |
| vmax | אחוז מהצד הגדול של החלון | 50vmax |
| cm | סנטימטר | 5cm |
| mm | מילימטר | 20mm |
| in | אינץ' | 2in |
| pt | נקודות | 12pt |
| pc | פיקה | 2pc |
דוגמה
.box {
width: 50%;
height: 100vh;
padding: 2rem;
margin: 10px;
}
2. רוחב וגובה
Width
.box {
width: 200px;
width: 50%;
width: 100vw;
width: auto;
width: fit-content;
width: max-content;
width: min-content;
}
Height
.box {
height: 300px;
height: 100%;
height: 100vh;
height: auto;
}
Min / Max
.box {
min-width: 100px;
max-width: 1200px;
min-height: 100px;
max-height: 800px;
}
אין טווח מספרי אחיד לכל הערכים
3. Margin ו-Padding
Margin - רווח חיצוני
.box {
margin: 10px;
margin: 10px 20px;
margin: 10px 20px 30px 40px;
margin-top: 10px;
margin-right: 20px;
margin-bottom: 30px;
margin-left: 40px;
margin: auto;
}
Padding - רווח פנימי
.box {
padding: 20px;
padding: 10px 20px;
padding-top: 10px;
padding-right: 20px;
padding-bottom: 30px;
padding-left: 40px;
}
4. טיפוגרפיה - Font
Font Size
font-size: 10px; font-size: 12px; font-size: 16px; font-size: 20px; font-size: 24px; font-size: 32px; font-size: 48px; font-size: 1rem; font-size: 2em; font-size: 150%; font-size: small; font-size: medium; font-size: large; font-size: x-large;
Font Weight
| ערך | משמעות |
|---|---|
| 100 | Thin |
| 200 | Extra Light |
| 300 | Light |
| 400 | Normal |
| 500 | Medium |
| 600 | Semi Bold |
| 700 | Bold |
| 800 | Extra Bold |
| 900 | Black |
Text Align
text-align: left; text-align: right; text-align: center; text-align: justify; text-align: start; text-align: end;
Text Decoration
text-decoration: none; text-decoration: underline; text-decoration: overline; text-decoration: line-through;
Line Height
line-height: normal; line-height: 1; line-height: 1.5; line-height: 2; line-height: 24px;
Letter Spacing
letter-spacing: normal; letter-spacing: 1px; letter-spacing: 2px; letter-spacing: -1px;
5. צבעים
color: red; color: blue; color: green; color: black; color: white; color: #ffffff; color: #000000; color: #ff0000; color: rgb(255, 0, 0); color: rgba(255, 0, 0, 0.5); color: hsl(120, 100%, 50%); color: hsla(120, 100%, 50%, 0.5); background-color: transparent;
RGB
כל ערוץ צבע נע בדרך כלל בין 0 ל-255.
HEX
שישה תווים הקובעים את צבעי RGB, או שלושה תווים בצורה המקוצרת.
HSL
Hue: בדרך כלל 0–360 מעלות. Saturation ו-Lightness: בין 0% ל-100%.
6. שקיפות - Opacity
טווח: 0 עד 1.
opacity: 0; opacity: 0.1; opacity: 0.25; opacity: 0.5; opacity: 0.75; opacity: 1;
Opacity 0.3
Opacity 0.6
Opacity 1
7. גבולות - Border
border: 1px solid red; border: 2px dashed blue; border: 3px dotted green; border: none; border-width: 1px; border-width: 2px; border-width: 5px; border-style: solid; border-style: dashed; border-style: dotted; border-style: double; border-style: groove; border-style: ridge; border-style: inset; border-style: outset; border-color: red; border-radius: 0; border-radius: 10px; border-radius: 50%; border-radius: 100px;
8. צללים - Shadow
box-shadow: 0 2px 5px black; box-shadow: 0 5px 15px rgba(0,0,0,.3); box-shadow: 0 10px 30px rgba(0,0,0,.5); text-shadow: 2px 2px 5px black;
הערכים העיקריים של box-shadow הם היסט אופקי, היסט אנכי, טשטוש, התפשטות וצבע.
9. Display
display: block; display: inline; display: inline-block; display: flex; display: inline-flex; display: grid; display: inline-grid; display: table; display: none; display: contents;
10. Position
position: static; position: relative; position: absolute; position: fixed; position: sticky;
מיקום האלמנט
top: 0; right: 0; bottom: 0; left: 0; inset: 10px; inset: 10px 20px;
Z-Index
z-index: -1; z-index: 0; z-index: 1; z-index: 10; z-index: 100; z-index: 9999;
11. Flexbox
Flex Direction
flex-direction: row; flex-direction: row-reverse; flex-direction: column; flex-direction: column-reverse;
Justify Content
justify-content: flex-start; justify-content: center; justify-content: flex-end; justify-content: space-between; justify-content: space-around; justify-content: space-evenly;
Align Items
align-items: flex-start; align-items: center; align-items: flex-end; align-items: stretch; align-items: baseline;
Flex Wrap
flex-wrap: nowrap; flex-wrap: wrap; flex-wrap: wrap-reverse;
Flex Properties
flex-grow: 0; flex-grow: 1; flex-shrink: 1; flex-shrink: 0; flex-basis: auto; flex-basis: 200px; gap: 10px; row-gap: 20px; column-gap: 15px;
12. CSS Grid
display: grid; grid-template-columns: 1fr 1fr; grid-template-columns: repeat(3, 1fr); grid-template-columns: 200px 1fr; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); grid-template-rows: 100px 200px; gap: 10px; row-gap: 20px; column-gap: 15px; grid-column: span 2; grid-row: span 2;
13. Transform
transform: none; transform: scale(1); transform: scale(1.5); transform: scaleX(2); transform: scaleY(2); transform: rotate(45deg); transform: rotateX(45deg); transform: rotateY(45deg); transform: translateX(100px); transform: translateY(50px); transform: translate(20px, 30px); transform: skew(10deg); transform: skewX(10deg); transform: skewY(10deg);
14. אנימציות ומעברים
Transition
transition: all 0.3s ease; transition-duration: 1s; transition-delay: 0.5s; transition-timing-function: linear; transition-timing-function: ease; transition-timing-function: ease-in; transition-timing-function: ease-out; transition-timing-function: ease-in-out;
Animation
animation-name: move; animation-duration: 2s; animation-delay: 1s; animation-iteration-count: infinite; animation-direction: alternate; animation-fill-mode: forwards; animation-timing-function: linear;
Keyframes
@keyframes move {
0% {
transform: translateX(0);
}
50% {
transform: translateX(100px);
}
100% {
transform: translateX(0);
}
}
15. פונקציות CSS
Calc
width: calc(100% - 50px); height: calc(100vh - 100px);
Min
width: min(100%, 1200px);
Max
width: max(50%, 400px);
Clamp
font-size: clamp(16px, 3vw, 32px);
Var
:root {
--main-color: blue;
}
.box {
color: var(--main-color);
}
Other Functions
width: min(100%, 500px); width: max(300px, 50%); width: clamp(200px, 50%, 800px); background: linear-gradient(red, blue); background: radial-gradient(circle, red, blue); filter: blur(5px); filter: brightness(1.2); filter: grayscale(100%);
16. Pseudo Classes ו-Pseudo Elements
Pseudo Classes
a:hover {}
a:active {}
a:visited {}
input:focus {}
input:checked {}
input:disabled {}
input:enabled {}
li:first-child {}
li:last-child {}
li:nth-child(2) {}
li:nth-child(odd) {}
li:nth-child(even) {}
:not(.active) {}
:root {}
Pseudo Elements
p::before {
content: "★";
}
p::after {
content: "!";
}
p::first-letter {}
p::first-line {}
::selection {}
::placeholder {}
17. Responsive Design
/* Mobile */
@media (max-width: 600px) {
.container {
width: 100%;
}
}
/* Tablet */
@media (min-width: 601px) and (max-width: 900px) {
.container {
width: 90%;
}
}
/* Desktop */
@media (min-width: 901px) {
.container {
width: 80%;
}
}
טווחים לדוגמה
| מסך | רוחב לדוגמה |
|---|---|
| טלפון קטן | עד 480px |
| טלפון | עד 600px |
| טאבלט | 600px–900px |
| מחשב | 900px ומעלה |
| מסך רחב | 1200px ומעלה |
אלו נקודות שבירה נפוצות בלבד, ולא תקן מחייב.
18. משתנים ב-CSS
:root {
--primary: #6c8cff;
--secondary: #9c70ff;
--spacing: 20px;
--radius: 10px;
}
.box {
color: var(--primary);
padding: var(--spacing);
border-radius: var(--radius);
}
19. מאפייני CSS נוספים
Overflow
overflow: visible; overflow: hidden; overflow: scroll; overflow: auto; overflow-x: hidden; overflow-y: auto;
Cursor
cursor: auto; cursor: default; cursor: pointer; cursor: wait; cursor: move; cursor: not-allowed; cursor: grab; cursor: zoom-in;
Object Fit
object-fit: fill; object-fit: contain; object-fit: cover; object-fit: none; object-fit: scale-down;
Visibility
visibility: visible; visibility: hidden; visibility: collapse;
White Space
white-space: normal; white-space: nowrap; white-space: pre; white-space: pre-wrap; white-space: pre-line;
List Style
list-style: none; list-style: disc; list-style: circle; list-style: square; list-style: decimal;
Box Sizing
box-sizing: content-box; box-sizing: border-box;
Pointer Events
pointer-events: auto; pointer-events: none;
User Select
user-select: auto; user-select: none; user-select: text; user-select: all;