When we left off at the end of part one, we had our basic elements of the game laid out in HTML, but the computer has no idea what they’re supposed to look like so it shows nothing; let’s change that using CSS.

Because everything is contained in the #game div, we should get the design for that laid out first :

Now let’s break down what the code above is telling us:

  • background-color: black; this one is pretty straightforward, the background color is going to be black.
  • height: 400px; & width: 400px; these are also pretty straightforward and just say that the game area is going to be a 400px square.
  • margin: 0 auto; this is saying that there should be no margin on the top or bottom, but the left and right margins should be automatically set. In effect, this is centering our game horizontally.
  • overflow: hidden; This line is saying that if something were to move outside of our game(we’ll make sure this can’t happen later, but it’s still good to protect against), it will not display on screen.
  • position: relative; This one is a little more complicated, but what we need to know is that any changes made to the games positioning will be relative to its original position

Right about now, you might be saying, “Great, we have a black square, but that’s a far cry from a game” and you’re right! We still need to design the rest of the elements and define how they behave. I’m going to take care of that first part for us now:

Let’s take a look at what we have made so far!

As you can see, we have our game area(black) with all of our elements(except bricks): the paddle(green), the projectile(white), the area where the bricks will go(pink).

I know what you’re saying: “This is a game about breaking bricks and we’ve seen no bricks! What gives?”

Well, the bricks are coming. In the next article, we’ll set up some JavaScript and get those bricks in there!

Software Engineering student at Flatiron School by night, Help Desk Analyst by day