<h2>Responsive Card Layout with Media Objects Made with Flexbox</h2>
<p>Use the buttons to add or remove cards to see how the layout behaves with different amounts of content.</p>
<button>Add Card</button> <button>Remove Card</button>
<main class="container">
<div class="card">
<div class="img"></div>
<div class="content"><h3>Card Title</h3><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p></div>
</div>
<div class="card">
<div class="img"></div>
<div class="content"><h3>Card Title</h3><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p></div>
</div>
<div class="card">
<div class="img"></div>
<div class="content"><h3>Card Title</h3><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p></div>
</div>
<div class="card">
<div class="img"></div>
<div class="content"><h3>Card Title</h3><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p></div>
</div>
<div class="card">
<div class="img"></div>
<div class="content"><h3>Card Title</h3><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p></div>
</div>
<div class="card">
<div class="img"></div>
<div class="content"><h3>Card Title</h3><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p></div>
</div>
</div>
</main>
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
font-size: 1.3em;
padding: 0 1em 2em;
line-height: 1.4;
text-align: center;
}
h2 {
margin: 14px 0;
text-align: center;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
padding: 1em 0;
text-align: left;
}
.card {
width: 30%;
display: flex;
background: #eee;
padding: .6em 1em .6em .6em;
margin-bottom: 1em;
border-radius: .3em;
box-shadow: rgba(0, 0, 0, 0.2) 3px 6px 10px;
border: solid 1px #ccc;
}
.img {
min-width: 80px;
height: 80px;
border-radius: .3em;
background: linear-gradient(to bottom, #d6c091 0%, #C05C9A 100%);
opacity: .7;
margin: 0 .6em 0 0;
border: solid 1px firebrick;
}
.card h3 {
margin: 0;
font-size: 1em;
}
.content p {
margin: 0;
font-size: .7em;
color: #222;
}
@media (max-width: 820px) {
.container {
min-width: auto;
display: block;
}
.card {
width: 100%;
}
}
@media (max-width: 480px) {
.card {
box-shadow: none;
}
}
document.querySelector('button').addEventListener('click', function () {
document.querySelector('main')
.appendChild(document.querySelector('.card').cloneNode(true));
}, false);
document.querySelectorAll('button')[1].addEventListener('click', function () {
if (document.querySelectorAll('.card')[1]) {
document.querySelector('.card').remove();
}
}, false);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.