Styling the Main Content
Style the About and Services sections with CSS — layout, cards, spacing, and visual design.
Styling the Main Content
With the header and hero styled, let's move on to the main content sections — the About area and the Services grid. We'll use Flexbox for layout and create polished card components.
Section Title Styling
.section-title {
text-align: center;
font-size: 32px;
font-weight: 700;
margin-bottom: 40px;
color: #333;
position: relative;
padding-bottom: 15px;
}
/* Decorative underline */
.section-title::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 60px;
height: 3px;
background: #31A8FF;
}
About Section Layout
#about {
padding: 80px 0;
background: #fff;
}
.about-content {
display: flex;
align-items: center;
gap: 40px;
}
.about-img {
flex: 1;
}
.about-img img {
width: 100%;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
.about-text {
flex: 1;
}
.about-text p {
margin-bottom: 16px;
font-size: 16px;
color: #555;
line-height: 1.8;
}
Flexbox Layout Explained
| Property | What It Does |
|---|---|
display: flex | Creates a flex container — children sit side by side |
gap: 40px | Adds consistent spacing between flex items |
flex: 1 | Each child takes equal available space |
align-items: center | Vertically centers the items |
Services Section Layout
#services {
padding: 80px 0;
background: #f4f4f4;
}
.services-grid {
display: flex;
gap: 30px;
}
Service Card Styling
.service-card {
flex: 1;
background: #fff;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.service-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}
.service-card img {
width: 100%;
height: 200px;
object-fit: cover;
}
.service-card h3 {
font-size: 20px;
padding: 20px 20px 10px;
color: #333;
}
.service-card p {
padding: 0 20px 20px;
font-size: 15px;
color: #666;
line-height: 1.6;
}
The object-fit Property
The object-fit: cover property is essential for image cards:
- It makes the image fill the container completely
- It crops the image if the aspect ratio doesn't match
- Combined with a fixed
height, it gives uniform card images regardless of the original photo dimensions
/* Other useful values */
object-fit: contain; /* Fit inside without cropping */
object-fit: fill; /* Stretch to fill (distorts) */
object-fit: none; /* Original size, may overflow */
Card Design Patterns
Well-designed cards follow these patterns:
- Overflow: hidden — clips the image to the card's border-radius
- Box-shadow — adds subtle depth
- Hover transform — lifts the card on hover for interactivity
- Consistent padding — uniform spacing inside the card
- Visual hierarchy — image → title → description
Adding a Subtle Background Pattern
/* Optional: light pattern for visual interest */
#services {
background: #f4f4f4 url('../img/bg-pattern.png') repeat;
}
Key Takeaways
- Use Flexbox with
gapfor clean grid layouts - The
::afterpseudo-element creates decorative section underlines object-fit: coverensures uniform image sizes across cards- Card components use overflow, shadow, and hover transforms for polish
- Consistent vertical padding on sections creates visual rhythm