How can I make a DIV change its color in the next instance of it?
TwointwoIcangeneratethiseffect:
For the chess effect, you should do it as follows:
.container {
width: 560px;
}
.container div {
float: left;
width: 50%;
height: 40px;
}
.container div:nth-child(4n - 3),
.container div:nth-child(4n) {
background-color: gainsboro;
}
.container div:nth-child(4n - 2),
.container div:nth-child(4n - 1) {
background-color: silver;
}
<div class="container">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
You can make use of odd and even css. It would look like this:
div{
width: 150px;
height: 150px;
color: #fff;
font-size: 25px;
text-align: center;
font-family: Arial;
display: table-cell;
vertical-align: middle;
}
div:nth-child(odd) {
background-color:#222222;
}
div:nth-child(even) {
background-color:#292929;
}
<div>DIV 01</div>
<div>DIV 02</div>
<div>DIV 03</div>
<div>DIV 04</div>
<!DOCTYPE html>
<html>
<head>
<title>DIV SUA LINDA! ;)</title>
</head>
<style type="text/css">
.clara{
background-color: #000000;
}
.escura{
background-color: #696969;
}
.div{
width: 623px;
height: 200px;
}
#box1{
float: left;
}
#box2{
float: right;
}
</style>
<body>
<div id="box1">
<div id="div1" class="clara div"></div>
<div id="div1" class="escura div"></div>
<div id="div1" class="clara div"></div>
</div>
<div id=box2>
<div id="div1" class="escura div"></div>
<div id="div1" class="clara div"></div>
<div id="div1" class="escura div"></div>
</div>
</body>
</html>