Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Animate CSS border-spacing property
The CSS border-spacing property controls the distance between the borders of adjacent table cells. When animated, it creates a dynamic effect where the spacing between cells changes smoothly over time.
Syntax
selector {
border-spacing: value;
animation: animation-name duration timing-function;
}
Example
The following example animates the border-spacing property from 0px to 20px −
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: separate;
border-spacing: 0px;
border: 2px solid #333;
animation: spacingAnimation 3s infinite alternate;
}
th, td {
border: 1px solid #4CAF50;
padding: 10px;
text-align: center;
background-color: #f9f9f9;
}
th {
background-color: #4CAF50;
color: white;
}
@keyframes spacingAnimation {
0% {
border-spacing: 0px;
}
100% {
border-spacing: 20px;
}
}
</style>
</head>
<body>
<h2>Animated Border Spacing</h2>
<table>
<tr>
<th>Subject</th>
<th>Student</th>
<th>Marks</th>
</tr>
<tr>
<td>Maths</td>
<td>Amit</td>
<td>98</td>
</tr>
<tr>
<td>Science</td>
<td>Sachin</td>
<td>99</td>
</tr>
</table>
</body>
</html>
A table with green headers and borders appears on the page. The spacing between table cells animates smoothly from 0px to 20px and back, creating a breathing effect where the cells move apart and come together continuously.
Key Points
When animating border-spacing, remember these important points −
- The table must have
border-collapse: separatefor border-spacing to work - You can animate both horizontal and vertical spacing using two values
- The animation creates smooth transitions between different spacing values
Conclusion
Animating the border-spacing property creates engaging visual effects for tables. It works only with separated borders and can enhance user interface designs with smooth spacing transitions.
Advertisements
