6 questions โ Basic to Advanced ยท Click to expand ยท + for code & details
The CSS Box Model describes how every HTML element is rendered as a rectangular box consisting of four layers from inside out: Content (actual text/image), Padding (space between content and border), Border (the element's border), and Margin (space outside the border between other elements).
By default, width/height applies to the content only.
Using box-sizing: border-box makes width/height include padding and border, which is much more intuitive and is the modern default in most CSS resets.
/* Box model layers */
.box {
width: 300px; /* content width */
height: 100px; /* content height */
padding: 20px; /* inside space */
border: 2px solid #2d6446;
margin: 16px; /* outside space */
/* Default (content-box):
total width = 300 + 20*2 + 2*2 = 344px */
box-sizing: border-box;
/* border-box:
total width = 300px (padding+border included)
content width = 300 - 40 - 4 = 256px */
}
/* Modern reset: apply border-box globally */
*,
*::before,
*::after {
box-sizing: border-box;
}| EMP_ID | EMP_NAME | DEPT_ID | SALARY |
|---|---|---|---|
| 101 | Alice Johnson | 10 | 50,000 |
| 102 | Bob Smith | 20 | 62,000 |
| 103 | Carol White | 10 | 55,000 |
| 104 | Dave Brown | 20 | 70,000 |
All 4 rows returned from employees table
The CSS Box Model describes how every HTML element is rendered as a rectangular box consisting of four layers from inside out: Content (actual text/image), Padding (space between content and border), Border (the element's border), and Margin (space outside the border between other elements).
Flexbox is a one-dimensional layout system โ it arranges items along a single axis (either row or column).
It is best for components like navigation bars, button groups, and centering content.
CSS Grid is a two-dimensional layout system โ it controls both rows and columns simultaneously.
It is best for overall page layouts, card grids, and complex two-dimensional arrangements.
They are complementary: use Grid for page layout structure and Flexbox for arranging items within components.
/* FLEXBOX: one-dimensional (row or column) */
.nav {
display: flex;
align-items: center; /* vertical centre */
justify-content: space-between; /* spread items */
gap: 16px;
}
.card-actions {
display: flex;
flex-direction: column; /* stack vertically */
gap: 8px;
}
/* CSS GRID: two-dimensional (rows AND columns) */
.page-layout {
display: grid;
grid-template-columns: 250px 1fr 300px; /* sidebar | main | aside */
grid-template-rows: 64px 1fr 80px; /* header | content | footer */
grid-template-areas:
"header header header"
"sidebar main aside"
"footer footer footer";
min-height: 100vh;
}
.main-content { grid-area: main; }
.sidebar { grid-area: sidebar; }| EMP_ID | EMP_NAME | DEPT_ID | SALARY |
|---|---|---|---|
| 101 | Alice Johnson | 10 | 50,000 |
| 102 | Bob Smith | 20 | 62,000 |
| 103 | Carol White | 10 | 55,000 |
| 104 | Dave Brown | 20 | 70,000 |
All 4 rows returned from employees table
Flexbox is a one-dimensional layout system โ it arranges items along a single axis (either row or column).
CSS custom properties (variables) are entities defined using double-dash prefix (--variable-name) in a :root or any CSS rule.
They are accessed with the var() function.
Unlike preprocessor variables (Sass/Less), CSS custom properties are dynamic โ they can be changed at runtime with JavaScript, are inherited through the DOM, and can be scoped to specific components.
They are heavily used in APEX Universal Theme for theming (colors, spacing, fonts).
/* Define variables in :root (global scope) */
:root {
--color-primary: #2d6446;
--color-secondary: #f5f0e8;
--font-size-base: 16px;
--border-radius: 8px;
--spacing-md: 16px;
}
/* Use variables */
.button {
background: var(--color-primary);
padding: var(--spacing-md);
border-radius: var(--border-radius);
font-size: var(--font-size-base);
}
/* Override in component scope */
.card {
--color-primary: #1e40af; /* local override */
background: var(--color-primary); /* uses blue here */
}
/* Change at runtime with JavaScript */
document.documentElement.style
.setProperty('--color-primary', '#7c3aed');| EMP_ID | EMP_NAME | DEPT_ID | SALARY |
|---|---|---|---|
| 101 | Alice Johnson | 10 | 50,000 |
| 102 | Bob Smith | 20 | 62,000 |
| 103 | Carol White | 10 | 55,000 |
| 104 | Dave Brown | 20 | 70,000 |
All 4 rows returned from employees table
CSS custom properties (variables) are entities defined using double-dash prefix (--variable-name) in a :root or any CSS rule.
CSS specificity determines which style rule wins when multiple rules target the same element.
It is calculated as a 4-part score (a, b, c, d): a = inline styles (1000), b = ID selectors (100 each), c = class/attribute/pseudo-class selectors (10 each), d = element/pseudo-element selectors (1 each).
Higher specificity wins.
If equal, the later rule wins (cascade). !important overrides all specificity but should be avoided as it breaks the cascade.
/* Specificity scores (a, b, c, d) */
p { color: black; } /* 0,0,0,1 = 1 */
.highlight { color: yellow; } /* 0,0,1,0 = 10 */
div.highlight { color: orange; } /* 0,0,1,1 = 11 */
#header { color: blue; } /* 0,1,0,0 = 100 */
#header .highlight { color: green; } /* 0,1,1,0 = 110 */
/* style="..." */ /* 1,0,0,0 = 1000*/
/* Example: which color wins? */
<p id="title" class="highlight">Text</p>
/* p = 1 โ black */
/* .highlight = 10 โ yellow */
/* #title = 100 โ BLUE wins! */
/* !important: overrides everything (avoid) */
.btn { color: red !important; } /* overrides even inline */
/* Tip: keep specificity low for maintainability */
/* Use classes, avoid IDs in CSS */| EMP_ID | EMP_NAME | DEPT_ID | SALARY |
|---|---|---|---|
| 101 | Alice Johnson | 10 | 50,000 |
| 102 | Bob Smith | 20 | 62,000 |
| 103 | Carol White | 10 | 55,000 |
| 104 | Dave Brown | 20 | 70,000 |
All 4 rows returned from employees table
CSS specificity determines which style rule wins when multiple rules target the same element.
Responsive web design makes web pages render well on all screen sizes โ desktops, tablets, and phones.
It uses three core techniques: fluid layouts (percentage widths instead of fixed pixels), flexible images (max-width: 100%), and CSS media queries (apply different styles at different viewport widths).
The viewport meta tag is also essential.
Mobile-first approach writes base styles for mobile and uses min-width media queries to enhance for larger screens.
/* Viewport meta tag (essential) */
/* <meta name="viewport" content="width=device-width, initial-scale=1.0"> */
/* Mobile-first: base styles for small screens */
.container {
width: 100%;
padding: 16px;
}
.cards-grid {
display: grid;
grid-template-columns: 1fr; /* 1 column on mobile */
gap: 16px;
}
/* Tablet: 2 columns */
@media (min-width: 600px) {
.cards-grid {
grid-template-columns: repeat(2, 1fr);
}
}
/* Desktop: 3 columns */
@media (min-width: 1024px) {
.container {
max-width: 1200px;
margin: 0 auto;
padding: 32px 48px;
}
.cards-grid {
grid-template-columns: repeat(3, 1fr);
}
}
/* Flexible images */
img {
max-width: 100%;
height: auto;
}| EMP_ID | EMP_NAME | DEPT_ID | SALARY |
|---|---|---|---|
| 101 | Alice Johnson | 10 | 50,000 |
| 102 | Bob Smith | 20 | 62,000 |
| 103 | Carol White | 10 | 55,000 |
| 104 | Dave Brown | 20 | 70,000 |
All 4 rows returned from employees table
Responsive web design makes web pages render well on all screen sizes โ desktops, tablets, and phones.
CSS transitions provide smooth property changes between two states triggered by events like hover or class changes.
They are defined with transition shorthand specifying property, duration, easing, and delay.
CSS animations use @keyframes to define multi-step animated sequences that play automatically or on loop.
Animations support timing functions, iteration count, direction, and fill mode.
Both use GPU acceleration for smooth 60fps performance when animating transform and opacity.
/* TRANSITION: smooth change on state change */
.button {
background: #2d6446;
transform: translateY(0);
transition: all 0.2s ease; /* property duration easing */
}
.button:hover {
background: #3a7d57;
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(45,100,70,0.3);
}
/* ANIMATION: multi-step, plays automatically */
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.card {
animation: fadeInUp 0.4s ease forwards;
}
/* Loading spinner */
@keyframes spin {
to { transform: rotate(360deg); }
}
.spinner {
animation: spin 0.8s linear infinite;
}| EMP_ID | EMP_NAME | DEPT_ID | SALARY |
|---|---|---|---|
| 101 | Alice Johnson | 10 | 50,000 |
| 102 | Bob Smith | 20 | 62,000 |
| 103 | Carol White | 10 | 55,000 |
| 104 | Dave Brown | 20 | 70,000 |
All 4 rows returned from employees table
CSS transitions provide smooth property changes between two states triggered by events like hover or class changes.