Expand div via CSS overflow
One way of doing this is to write css where you set a height on your div and set the overflow to hidden.
After a click on the div, the overflow can be set to visible:
HTML
<div class='container'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non felis eu massa dictum rutrum ac et massa. Morbi ante ante, faucibus non varius ut, sollicitudin blandit libero. Nam magna elit, molestie et nulla in, aliquam sagittis enim. Donec eget nulla
hendrerit, molestie dui at, ultrices sapien...
</div>
CSS
.container {
height: 1.5rem;
overflow: hidden;
}
JavaScript
$(document).ready(function() {
$(".container").click(function() {
$(this).css("overflow", "visible");
});
});
CodePen Demo
Expand and hide div via CSS overflow and JQuery's toggleClass
If you want to show and hide the text when clicking on the div, you can use the same css overflow strategy and toggle the class in JQuery like so:
HTML
<div class='container'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non felis eu massa dictum rutrum ac et massa. Morbi ante ante, faucibus non varius ut, sollicitudin blandit libero. Nam magna elit, molestie et nulla in, aliquam sagittis enim. Donec eget nulla
hendrerit, molestie dui at, ultrices sapien...
</div>
CSS
.container {
height: 1.5rem;
overflow: hidden;
}
.container:hover {
cursor: pointer;
}
.expand {
overflow: visible;
}
JavaScript
$(document).ready(function() {
$(".container").click(function() {
$(this).toggleClass("expand");
});
});
CodePen Demo
Animate in a child div via JQuery's slideDown
If you want to animate it, you can show and hide the text you want to expand. I used a div for the additional expanded text so it is forced onto the next line (this is more responsive friendly):
HTML
<div class='container'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non felis eu massa
dictum rutrum ac et massa. Morbi ante ante, faucibus non varius ut, sollicitudin blandit libero.
<div id='more'>
Nam magna elit, molestie et nulla in, aliquam sagittis enim. Donec eget nulla hendrerit,
molestie dui at, ultrices sapien. In iaculis nunc sapien, sit amet iaculis velit viverra in. Proin in massa magna. Nullam volutpat...
</div>
</div>
CSS
.container:hover {
cursor: pointer;
}
#more {
display: none;
}
JavaScript
$(document).ready(function() {
$(".container").click(function() {
if ($("#more").is(":hidden")) {
$("#more").slideDown("fast");
} else {
$("#more").hide();
}
});
});
CodePen Demo