Introduction
In this lab, we will learn how to create a zig zag background pattern using CSS. By using linear-gradient() and adjusting the background-size and background-position, we will be able to create a visually appealing pattern that can be used on various elements of a website. This lab will help improve our CSS skills and give us a better understanding of how to use CSS to create unique designs.
Zig Zag Background Pattern
index.html and style.css have already been provided in the VM.
To create a zig zag background pattern, use the following steps:
- Set a white background using
background-color. - Create the parts of a zig zag pattern using
background-imagewith fourlinear-gradient()values. - Specify the pattern's size using
background-size. - Place the parts of the pattern in the correct locations using
background-position. - To repeat the pattern, use
background-repeat. - Note: The
heightandwidthof the element are fixed for demonstration purposes only.
Here is an example code snippet:
<div class="zig-zag"></div>
.zig-zag {
width: 240px;
height: 240px;
background-color: #fff;
background-image:
linear-gradient(135deg, #000 25%, transparent 25%),
linear-gradient(225deg, #000 25%, transparent 25%),
linear-gradient(315deg, #000 25%, transparent 25%),
linear-gradient(45deg, #000 25%, transparent 25%);
background-position:
-30px 0,
-30px 0,
0 0,
0 0;
background-size: 60px 60px;
background-repeat: repeat;
}
Please click on 'Go Live' in the bottom right corner to run the web service on port 8080. Then, you can refresh the Web 8080 Tab to preview the web page.
Summary
Congratulations! You have completed the Zig Zag Background Pattern lab. You can practice more labs in LabEx to improve your skills.