Creating a modern card style: trendy use of CSS properties
Creating a Modern Card Style: Trendy Use of CSS Properties
1. Preface
Card layouts have become a very common design pattern in modern web design. Card layouts are simple, intuitive, and suitable for displaying various types of information. This article will introduce some commonly used CSS properties and how to use them to create modern card styles.
2. Flexbox Layout
Flexbox is a flexible box layout model in CSS3 Tutorial , used to describe the layout of child elements within a container. By using Flexbox, we can easily implement a card layout.
.card-container {
display: flex;
flex-wrap: wrap;
}
.card {
width: 300px;
height: 200px;
background-color: #f1f1f1;
margin: 10px;
padding: 20px;
border-radius: 5px;
}
In the above code, we create a card container .card-container
and a card .card
. By setting display: flex
, we transform the card container into a flexible container, automatically arranging the card elements within it according to a flexible layout. flex-wrap: wrap
means that if the child elements do not fit on a single line, they will automatically wrap.
3. Grid Layout
Grid is a grid layout model in CSS3 Tutorial , and can also be used to implement card layouts. Unlike Flexbox, Grid is more suitable for two-dimensional layouts, allowing for more flexible definition of row and column sizing and positioning.
.card-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
}
.card {
width: 300px;
height: 200px;
background-color: #f1f1f1;
padding: 20px;
border-radius: 5px;
}
In the above code, we transform the card container .card-container
into a grid container by setting display: grid
. grid-template-columns: repeat(3, 1fr)
specifies that the container is divided into three columns, each of equal size. gap: 20px
means there’s a 20-pixel gap between each grid element.
4. CSS Variables
CSS Variables are a mechanism for storing and reusing values in CSS. By using CSS variables, we can modify and manage styles more flexibly.
.card {
--primary-color: #f1f1f1;
--secondary-color: #cccccc;
--border-radius: 5px;
width: 300px;
height: 200px;
background-color: var(--primary-color);
padding: 20px;
border-radius: var(--border-radius);
}
.card:hover {
background-color: var(--secondary-color);
}
In the above code, we use CSS variables to define the card’s color and border radius. By using the var()
function, we can reference these variables in our styles. This way, when we need to change the color or border radius, we simply modify the variable’s value.
5. Animation Effects
To increase interactivity and visual appeal, we can add some animation effects to the cards.
.card {
transition: transform 0.3s ease;
}
.card:hover {
transform: scale(1.1);
}
In the above code, we use CSS transitions and transform properties to enlarge the card when the mouse hovers. By defining the transition
property, we specify that the transition occurs over 0.3 seconds and use the ease
easing function to make the animation smoother.
6. Pure CSS Icons
To improve the readability and aesthetics of cards, we can add icons. These icons can be created using pure CSS without using any https://coder-cafe.com/wp-content/uploads/2025/09/images.
.card:before {
content: "f1f9";
font-family: "Font Awesome 5 Pro";
font-weight: 900;
margin-right: 8px;
}
.card:after {
content: "f02e";
font-family: "Font Awesome 5 Pro";
font-weight: 900;
margin-left: 8px;
}
In the code above, we add icons to the left and right sides of the card by using the CSS pseudo-elements :before
and :after
and setting the content
property to the desired Unicode character code. We also reference the font “Font Awesome 5 Pro,” which contains many common icons.
7. Responsive Design
Responsive design is crucial in modern web design. By using media queries, we can adjust the layout and style of cards for different device sizes.
@media (max-width: 768px) {
.card-container {
display: block;
}
}
@media (max-width: 480px) {
.card {
width: 100%;
}
}
In the code above, we use two media queries. When the device width is 768 pixels or less, the card container is displayed as a block element, meaning the cards are arranged vertically. When the device width is 480 pixels or less, the width of each card is set to 100%, so the cards occupy the entire width of the screen.
8. Conclusion
By flexibly utilizing various CSS properties, we can easily create modern card styles. This article introduced Flexbox layout, Grid layout, CSS variables, animation effects, pure CSS icons, and responsive design. We hope this helps you with your web design work. However, please remember that in your actual projects, you should choose and apply these techniques based on the specific situation to achieve the best results and user experience.