kyle lingat kyle lingat - 2 months ago 7
CSS Question

Creating a responsive website that changes color with CSS

Something similar to this

http://gomagames.com/blocks/blocks_sassy.html

How would this be achieved with css?

Answer

You can use @media rule in CSS.

This example change the background color of the body and the div tags depending of the screen size.

@media screen and (max-width: 400px) {
    body {
        background-color: lightgreen;
    }
    .mydiv {
      background-color:#000;
    }
}

@media screen and (min-width: 401px) and (max-width: 1000px) {
    body {
        background-color: green;
    }
    .mydiv {
      background-color:#444;
    }
}

@media screen and (min-width: 1001px) {
    body {
        background-color: blue;
    }
    .mydiv {
      background-color:#999;
    }
}

.mydiv {
  width:100%;
  height:20px;
  margin:10px 0;
}
<div class="mydiv">
</div>
<div class="mydiv">
</div>
<div class="mydiv">
</div>