Checkerboard Background Pattern

CSSCSSBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In this lab, we will explore the world of CSS programming and learn how to create a checkerboard background pattern using advanced CSS techniques. The lab will guide you through the steps required to create a visually appealing checkerboard pattern that can be used in various web design projects. By the end of this lab, you will have gained valuable experience in using CSS to create beautiful and engaging web designs.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL css(("`CSS`")) -.-> css/BasicConceptsGroup(["`Basic Concepts`"]) css(("`CSS`")) -.-> css/BasicStylingGroup(["`Basic Styling`"]) css(("`CSS`")) -.-> css/CoreLayoutGroup(["`Core Layout`"]) css(("`CSS`")) -.-> css/IntermediateStylingGroup(["`Intermediate Styling`"]) css/BasicConceptsGroup -.-> css/selectors("`Selectors`") css/BasicStylingGroup -.-> css/colors("`Colors`") css/CoreLayoutGroup -.-> css/width_and_height("`Width and Height`") css/IntermediateStylingGroup -.-> css/backgrounds("`Backgrounds`") subgraph Lab Skills css/selectors -.-> lab-35180{{"`Checkerboard Background Pattern`"}} css/colors -.-> lab-35180{{"`Checkerboard Background Pattern`"}} css/width_and_height -.-> lab-35180{{"`Checkerboard Background Pattern`"}} css/backgrounds -.-> lab-35180{{"`Checkerboard Background Pattern`"}} end

Checkerboard Background Pattern

index.html and style.css have already been provided in the VM.

To create a checkerboard background pattern, follow these steps:

  1. Set the background-color property to white.
  2. Use background-image with two linear-gradient() values, each with a different angle to create the checkerboard pattern. For example, set one angle to 45deg and the other to -45deg.
  3. Specify the pattern's size using background-size. For instance, 60px 60px will create a 60-by-60 pixel pattern.
  4. Use background-repeat to set the repetition of the pattern. For example, repeat will make the pattern repeat in both directions.
  5. Note that the height and width properties of the element are fixed to 240px for demonstration purposes.

Here's an example HTML element with the .checkerboard class:

<div class="checkerboard"></div>

And here's the corresponding CSS:

.checkerboard {
  width: 240px;
  height: 240px;
  background-color: #fff;
  background-image: linear-gradient(
      45deg,
      #000 25%,
      transparent 25%,
      transparent 75%,
      #000 75%,
      #000
    ),
    linear-gradient(
      -45deg,
      #000 25%,
      transparent 25%,
      transparent 75%,
      #000 75%,
      #000
    );
  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 Checkerboard Background Pattern lab. You can practice more labs in LabEx to improve your skills.

Other CSS Tutorials you may like