JSFiddle - React, Tailwind, and code Playground
by jeremykenedy
HTML
<body>
<div id="page-wrap">
<div class="sidebar-box black">
<p>Malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
<p class="read-more"><a href="#" class="button">Read More</a>
</p>
</div>
<div class="sidebar-box gray">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae</p>
<p>ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
<p class="read-more"><a href="#" class="button">Read More</a>
</p>
</div>
<div class="sidebar-box red">
<p>Et netus et malesuada fames ac turpis egestas. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
<p class="read-more"><a href="#" class="button">Read More</a>
...
CSS
* {
margin: 0;
padding: 0;
}
body {
font: 14px/1.5 Georgia, serif;
color: white;
background: black;
}
article, aside, figure, footer, header, hgroup, menu, nav, section {
display: block;
}
#page-wrap {
width: 960px;
margin: 80px auto;
}
h1 {
box-shadow: 0 0 20px black;
}
p {
margin: 0 0 15px 0;
}
.sidebar-box {
float: left;
width: 250px;
margin: 0 20px 0 0;
}
.sidebar-box {
max-height: 120px;
position: relative;
padding: 20px;
overflow: hidden;
}
.sidebar-box .read-more {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
text-align: center;
margin: 0;
padding: 30px 0 30px 0;
/* "transparent" only works here because == rgba(0,0,0,0) */
background-image: -moz-linear-gradient(top, transparent, black);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, transparent), color-stop(1, black));
}
.gray {
background-color: #444;
background-color: rgb(89, 89, 89);
}
.red {
background-color: red;
}
.red .read-more {
/* transparent doesn't work in this context, must use RGBa for both */
background-image: -moz-linear-gradient(top, rgba(255, 0, 0, 0), rgba(255, 0, 0, 100));
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, rgba(255, 0, 0, 0)), color-stop(1, rgba(255, 0, 0, 100)));
}
.button {
border-top: 1px solid #96d1f8;
background: #65a9d7;
background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7));
background: -moz-linear-gradient(top, #3e779d, #65a9d7);
padding: 5px 10px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
/* overboard shadows for Opera (and why spec version listed first) */
box-shadow: rgba(0, 0, 0, 1) 0 1px 0, rgba(0, 0, 0, 90) 0 0 10px, rgba(0, 0, 0, 90) 0 0 20px, rgba(0, 0, 0, 90) 0 0 30px;
-webkit-box-shadow: rgba(0, 0, 0, 1) 0 1px 0;
-moz-box-shadow: rgba(0, 0, 0,...
JavaScript
$(function () {
var $el, $ps, $up, totalHeight;
$(".sidebar-box .button").click(function () {
// IE 7 doesn't even get this far. I didn't feel like dicking with it. -FUNNY
totalHeight = 0
$el = $(this);
$p = $el.parent();
$up = $p.parent();
$ps = $up.find("p:not('.read-more')");
// measure how tall inside should be by adding together heights of all inside paragraphs (except read-more paragraph)
$ps.each(function () {
totalHeight += $(this).outerHeight();
// FAIL totalHeight += $(this).css("margin-bottom");
});
$up.css({
// Set height to prevent instant jumpdown when max height is removed
"height": $up.height(),
"max-height": 9999
})
.animate({
"height": totalHeight
});
// fade out read-more
//$p.fadeOut();
$('.read-more').click(function() {
$(this).find('a').addClass('read_less');
});
// prevent jump-down
return false;
});
});