Skip to content

Instantly share code, notes, and snippets.

@t0nic
Created November 9, 2018 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t0nic/48ee6d4a3128e85667d71fc76c01d203 to your computer and use it in GitHub Desktop.
Save t0nic/48ee6d4a3128e85667d71fc76c01d203 to your computer and use it in GitHub Desktop.
Flexy Dashboard Cards
<div id="container">
<body onresize="windowSizeChanged()">
<div class="card flexy"></div>
<div class="card flexy"></div>
<div class="card flexy"></div>
</div>
function windowSizeChanged() {
allCards = document.getElementById("container").querySelectorAll(".card");
firstCard = allCards[0];
firstCard.classList.add("first");
firstCardWidth = firstCard.offsetWidth;
lastCard = allCards[allCards.length - 1];
lastCard.innerHTML = "Width: " + firstCardWidth;
lastCard.classList.remove("flexy");
lastCard.style.width = firstCardWidth + "px";
lastCard.style.backgroundColor = "skyBlue";
return 0;
}
#container {
display: flex;
flex-wrap: wrap;
background-color: lightGrey;
padding: 10px;
max-width: 1500px;
}
.card {
background-color: teal;
margin: 25px;
height: 300px;
&:last-child {
// margin-right: 0;
}
}
.flexy {
flex-grow: 1;
min-width: 300px;
}
// important because the javascript is being overwritten
.first {
background-color: salmon !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment