DEV Community

TidyCoder
TidyCoder

Posted on

How to create a beautiful square in HTML CSS No JS

In this Article, you will learn how to create a very very very (...) beautiful square with only HTML and the perfect language: the CSS. At the same time you will learn new techniques to code properly.

Step 1: Create a simple square in HTML with a basic css code:

In this part, We will write a div in HTML and a primary color background to him.
Here the result with the HTML and CSS codes:

Step 2: Add simple squares, apply the style to the beautiful square (and align him the on the center of the body - optional):

Second fact, we will add squares to this beautiful square, with the grid-template-columns property, got it? Let's go, here the steps:

  1. Adding (In the HTML part) nine divs (here, the divs is the squares) to the parent div (here, the parent div is the square which contains the nine divs).
  2. Turn the display property to grid to active the grid-template-columns property to the parent div with this value: auto auto auto, That's why you will watch a 3x3 square in the final result. Why 3x3, because the one "three" is the number of times the word auto has been repeated and the two three for 9 (the number of divs) divided by 3 (the number of times the word auto has been repeated).
  3. Adding the with and the height of the parent div, turn the gap property to 1px or more (It's the space between the internal squares) and apply a soothing background color to him.
  4. Adding styles to the internal squares, a border-radius for example, and a soothing background color (this is important to making a difference between the background of the parent div and the internal squares, otherwise you will watch a unique bad square which have a one background color)...
  5. Add style to the parent div.
  6. The final instruction, and optional, add a background to the body, and align the beautiful square on the center of the body. Do you think to the beautiful result? Scroll and watch the beauty of the minimal code.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay