Created
June 26, 2018 20:04
-
-
Save MikeDigitize/fea242a085d63d1cdea811977c0f1946 to your computer and use it in GitHub Desktop.
CSS challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
.box { | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
margin: auto; | |
} | |
.red { | |
width: 300px; | |
height: 300px; | |
background-color: crimson; | |
} | |
.yellow { | |
width: 250px; | |
height: 250px; | |
background: gold; | |
} | |
.blue { | |
width: 200px; | |
height: 200px; | |
background: slateblue; | |
} | |
.green { | |
width: 150px; | |
height: 150px; | |
background: seagreen; | |
} | |
.orange { | |
width: 100px; | |
height: 100px; | |
background: orangered; | |
} | |
</style> | |
<div class="red box"> | |
<div class="yellow box"> | |
<div class="blue box"> | |
<div class="green box"> | |
<div class="orange box"></div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script> | |
(() => { | |
const container = document.body; | |
const colours = ['red', 'yellow', 'blue', 'green', 'orange']; | |
container.addEventListener('click', function(e) { | |
const { target } = e; | |
const selected = colours.filter(colour => target.className.includes(colour)).pop(); | |
alert(selected || 'no colour!'); | |
}); | |
})() | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment