Polka Dot Background Pattern

CSSCSSBeginner
Practice Now

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

Introduction

In this lab, we will explore the basics of CSS programming and learn how to use CSS to style and format web pages. Through a series of hands-on exercises, you will gain a solid understanding of CSS syntax, selectors, properties, and values, and be able to create visually appealing and responsive web pages. By the end of this lab, you will have a strong foundation in CSS and be ready to take on more advanced web development projects.


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/CoreLayoutGroup -.-> css/positioning("`Positioning`") css/IntermediateStylingGroup -.-> css/backgrounds("`Backgrounds`") subgraph Lab Skills css/selectors -.-> lab-35229{{"`Polka Dot Background Pattern`"}} css/colors -.-> lab-35229{{"`Polka Dot Background Pattern`"}} css/width_and_height -.-> lab-35229{{"`Polka Dot Background Pattern`"}} css/positioning -.-> lab-35229{{"`Polka Dot Background Pattern`"}} css/backgrounds -.-> lab-35229{{"`Polka Dot Background Pattern`"}} end

Polka Dot Background Pattern

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

To create a polka dot background pattern, you can follow these steps:

  1. Set the background-color property to black.
  2. Use the background-image property with two radial-gradient() values to create two dots.
  3. Specify the pattern's size using the background-size property. Use background-position to appropriately place the two gradients.
  4. Set background-repeat to repeat.
  5. Note that the fixed height and width of the element is for demonstration purposes only.

Here's an example HTML code for a div element with class polka-dot:

<div class="polka-dot"></div>

And here's the corresponding CSS code:

.polka-dot {
  width: 240px;
  height: 240px;
  background-color: #000;
  background-image: radial-gradient(#fff 10%, transparent 11%),
    radial-gradient(#fff 10%, transparent 11%);
  background-size: 60px 60px;
  background-position:
    0 0,
    30px 30px;
  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 Polka Dot Background Pattern lab. You can practice more labs in LabEx to improve your skills.

Other CSS Tutorials you may like