CSS ID changes

Hey, I guess this is probably pretty trivial, but it's hard for me to find an answer or understand it nonetheless.

I am trying to create a grid of colored squares with an arbitrary spacing between them. This in itself is easy to do, especially because I only need nine squares. But while I look at my code, I cannot help but feel that there is a much simpler and more efficient way to accomplish this.

At the moment, I have nine different identifiers declared in my CSS, one for each square.

div.container{
    position:relative;
    left:50px;
    top:50px;
    background-color:rgb(45,45,45);
    height:300px;
    width:300px;
}

#square{
    position:absolute;
    background-color:rgb(52,82,222);
    left:20px;
    top:20px;
    height:80px
    width:80px

#square2{
    position:absolute;
    background-color:rgb(58,82,22);
    left:110px;
    top:20px;
    height:80px;
    width:80px;


etc etc etc

What I would like to do is find a more efficient way to do this.

Thanks for the help!

+3
source share
3 answers

, div s, div, div width height, ,

.container {
    position: relative;
    left: 50px;
    top: 50px;
    background: rgb(45,45,45);
    height: 300px;
    width: 300px;
}
.container > div {
    position: absolute;
    background-color: rgb(52,82,222);
    height: 80px;
    width: 80px;
}

#square1 {
    left: 20px;
    top: 20px;
}
#square2 {
    left: 110px;
    top: 20px;
}
..

top left div, , id s.

class .container > div, div, .container.

HTML :

<div class="container">
    <div id="square1"></div>
    <div id="square2"></div>
    ..
</div>
+3

, :

.square {
    position: absolute;
    width: 80px;
    height: 80px;
}

, ? , .

div.container {
    width: 240px;
}

.square {
    float: left;
    width: 80px;
    height: 80px;
}
+4

-

.square
{
   display: inline-block;
   width: 80px;
   height: 80px;
   zoom: 1;
   *display: inline /* for IE */
}

, .

+1

All Articles