Comprehensive Web Design Guide
Border properties in CSS allow you to create and style borders around HTML elements. They are essential for defining the visual boundaries and enhancing the design of web pages. Borders can be customized in terms of style, width, color, and shape.
Key aspects of border properties include:
The border-style property specifies the type of border to display.
border-style: none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset |
The border-width defines the thickness of the border.
The border-color sets the color of the border.
Target specific sides of the border.
Combine width, style, and color in one declaration.
Create rounded corners for elements.
The `display` property in CSS determines how an element is displayed in the document. It influences the layout and interaction of an element with surrounding elements. Common values are:
Property | Width | Height | Margin | Padding |
---|---|---|---|---|
block | Can be set | Can be set | All sides apply | All sides apply |
inline | Cannot be set | Cannot be set | Horizontal margins apply | Horizontal padding applies |
inline-block | Can be set | Can be set | All sides apply | All sides apply |
Characteristic | Description |
---|---|
Width | Takes full width of parent container |
Line Behavior | Always starts on a new line |
Dimensions | Respects width and height properties |
Characteristic | Description |
---|---|
Width | Only takes necessary content width |
Line Behavior | Flows within text, no line breaks |
Dimensions | Ignores width and height settings |
Characteristic | Description |
---|---|
Width | Configurable content width |
Line Behavior | Flows inline with other elements |
Dimensions | Respects width and height properties |
Display Type | Recommended Use | Example Scenarios |
---|---|---|
Block | Layout Structures | Paragraphs, Divs, Sections |
Inline | Text-Based Elements | Spans, Links, Bold/Italic Text |
Inline-Block | Interactive Components | Buttons, Navigation Items |
What It Does: It creates a flexible layout system for arranging items in a container.
Why It’s Useful: It helps align and distribute items easily, even when their sizes vary.
Property | Description | Common Values |
---|---|---|
display: flex | Creates a flex container | flex, inline-flex |
justify-content | Aligns items horizontally | center, space-between, space-around |
align-items | Aligns items vertically | center, stretch, flex-start |
What It Does: It adds a shadow to an element, making it look like it's lifted off the page.
Why It’s Useful: It gives depth and a polished look to elements.
Property | Description | Value Components |
---|---|---|
box-shadow | Adds shadow effect to element | x-offset, y-offset, blur-radius, color |
Horizontal Offset | Shadow position on X-axis | Positive/Negative pixels |
Vertical Offset | Shadow position on Y-axis | Positive/Negative pixels |
What It Does: It decides how the size of an element is calculated (whether padding and border are included or excluded).
Why It’s Useful: It simplifies layout and ensures consistent element sizes.
Value | Description | Calculation Method |
---|---|---|
content-box | Default browser behavior | Width = content width |
border-box | Includes padding and border in total width | Width = content + padding + border |
What It Does: Controls how decorations like borders, backgrounds, and shadows behave when content breaks into multiple lines or boxes.
Why It’s Useful: Ensures a smooth or continuous look for elements split across lines.
Value | Description | Use Case |
---|---|---|
slice | Default behavior | Breaks background at element boundaries |
clone | Repeats decoration across lines | Multi-line text with consistent styling |
Defines the appearance of list markers. Can change bullets to different shapes or numbers to various numbering systems.
Controls whether list markers are inside or outside the list item's content box.
Replaces standard markers with a custom image. Useful for unique or branded list styles.
Combines list-style-type, list-style-position, and list-style-image in a single declaration.
Property | Values | Example |
---|---|---|
text-align | left, right, center, justify |
Centered Text
|
text-indent | pixels, ems, percentage |
Indented first line by 30 pixels
|
line-height | normal, number, pixels, percentage |
Double line height
Increased spacing between lines |
letter-spacing | normal, pixels |
Increased space between characters
|
text-decoration | none, underline, overline, line-through |
Underlined Text
|
Property | Values | Example |
---|---|---|
font-family |
- Generic families: serif, sans-serif, monospace - Specific fonts: Arial, Times New Roman, Helvetica - Web fonts: Google Fonts, Custom Fonts - System fonts: system-ui |
Times New Roman Text
Arial Text
Monospace Text
|
font-style |
- normal - italic - oblique |
Normal text
Italic text
Oblique text
|
font-weight |
- normal (400) - bold (700) - lighter - bolder - 100 to 900 |
Normal weight (400)
Bold weight (700)
Heavy weight (900)
|
font-size |
- Absolute: px, pt - Relative: em, rem, % - Keywords: small, medium, large - Viewport: vw, vh |
12px text size
1.5em text size
Large text size
|
text-decoration |
- none - underline - overline - line-through - Can combine with style and color |
No decoration
Underlined text
Strikethrough text
Fancy decoration
|
Property | Values | Example |
---|---|---|
background-color | color name, hex, rgb, rgba |
background-color: blue;
background-color: #3498db;
background-color: rgb(52, 152, 219);
|
background-image | url(), linear-gradient(), radial-gradient() |
background-image: url('image.jpg');
background-image: linear-gradient(to right, red, blue);
|
background-position | top, bottom, left, right, center, px, % |
background-position: center;
background-position: 25% 75%;
background-position: 50px 100px;
|
background-size | cover, contain, px, % |
background-size: cover;
background-size: contain;
background-size: 200px 150px;
background-size: 50% 100%;
|
The CSS position property defines how an element is positioned in a document. It can change an element's layout behavior and its relationship to other elements.
Property Value | Description | Example |
---|---|---|
static | Default positioning. Element follows normal document flow. |
position: static;
/* Default behavior, no special positioning */
|
relative | Positioned relative to its normal position. Doesn't affect other elements. |
position: relative;
top: 20px; /* Moves 20px down */
left: 30px; /* Moves 30px right */
|
absolute | Removed from normal document flow. Positioned relative to nearest positioned ancestor. |
position: absolute;
top: 50px;
right: 100px;
|
fixed | Positioned relative to the browser window. Stays in the same place during scrolling. |
position: fixed;
bottom: 20px;
right: 20px; /* Stays in bottom-right corner */
|
sticky | Toggles between relative and fixed positioning based on scroll position. |
position: sticky;
top: 0; /* Sticks to top when scrolled */
|
The positioning of elements depends on their context:
CSS provides powerful properties to style and control HTML tables, allowing for more dynamic and visually appealing table designs.
Property | Description | Example |
---|---|---|
border | Controls table and cell border appearance |
table {
border: 2px solid #333;
}
td {
border: 1px solid #ddd;
}
|
border-collapse | Defines how table borders are rendered |
/* Combines adjacent cell borders */
table {
border-collapse: collapse;
/* or */
border-collapse: separate;
}
|
width & height | Set table and cell dimensions |
table {
width: 100%;
height: 400px;
}
td {
width: 50%;
height: 50px;
}
|
text-align | Horizontal alignment of cell content |
td {
text-align: left; /* left, center, right */
}
|
vertical-align | Vertical alignment of cell content |
td {
vertical-align: middle; /* top, middle, bottom */
}
|
Name | Role |
---|---|
Alice | Developer |
Bob | Designer |
Charlie | Manager |
Product | Price |
---|---|
Laptop | $999 |
Smartphone | $599 |
Tablet | $399 |
Headphones | $199 |
Table borders define the visual boundaries of tables and cells. You can control:
This property determines how table borders are rendered:
collapse
: Combines adjacent cell borders into a single borderseparate
: Keeps cell borders distinct with spacingControl table and cell dimensions using percentage or pixel values:
Positioning content within table cells:
text-align
: Aligns content horizontally (left, center, right)vertical-align
: Aligns content vertically (top, middle, bottom)Add interactivity by changing background on hover using :hover
pseudo-class
Improve readability by adding alternating background colors using :nth-child()
selector