- index.html
- style.css
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Repeating Linear Gradient</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="box gradient-1"></div>
<div class="box gradient-2"></div>
<div class="box gradient-3"></div>
<div class="box gradient-4"></div>
</div>
</body>
</html>
CSS
html,
body {
margin: 0;
padding: 0;
}
.container {
margin: 20px auto;
width: 440px;
height: 440px;
}
.box {
float: left;
margin: 10px;
width: 200px;
height: 200px;
box-shadow: 0 0 3px #666666;
}
/* The simplest option, which will create sharp boundaries when repeated */
.gradient-1 {
background-image: linear-gradient(black 0, green 25px, yellow 50px);
}
/* Added sharp transitions inside the gradient.
When repeated, we get stripes */
.gradient-2 {
background-image: linear-gradient(black 0, black 17px, green 17px, green 33px, yellow 33px, yellow 50px);
}
/* Avoid sharp transitions when it is repeated */
.gradient-3 {
background-image: linear-gradient(black 0, green 25px, yellow 50px, black 75px);
}
/* Color stops specified as percentages; two repeats will always fit in a block regardless of its size */
.gradient-4 {
background-image: linear-gradient(black 0, green 25%, yellow 50%);
}
You’ve gone to a different page
Goalscompleted
0
Change the linear gradient to a repeating one for the four blocks.
- First block.
- Second block.
- Third block.
- Fourth block.
Comments