Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand a div and its contents on hover?

Tags:

html

css

expand

I'm trying to create a div that expands on hover, but cannot figure out how to make the content expand with the div. I've tried a few overflow options, but they didn't work.

.grow {
  padding: 5px 5px 5px 5px;
  border-radius:10px;
    height: 50px; 
    width: 22%; 
    margin: 5px 1% 5px 1%; 
    float: left; 
    position: relative; 
    transition:height 0.5s; 
    -webkit-transition:height 0.5s; 
    text-align: center;

}
.grow:hover {
    height: 115px; /* This is the height on hover */
}
<div class="grow" style="background-color: #2a75a9;">
    <h2>Title</h2> <br>
    Contrary to popular belief, Lorem Ipsum is not simply random text.  It has roots in a piece of classical Latin literature
</div>

Here is the JSFiddle

like image 886
Nicole Avatar asked Dec 12 '14 10:12

Nicole


2 Answers

Add overflow: hidden to the parent(.grow) container to hide the description. This will reveal the description on hover.

Additionally, instead of using the <br /> tag, wrap the text in a <p> tag.

.grow {
  padding: 5px 5px 5px 5px;
  border-radius: 10px;
  height: 49px;
  width: 22%;
  margin: 5px 1% 5px 1%;
  float: left;
  position: relative;
  transition: height 0.5s;
  -webkit-transition: height 0.5s;
  text-align: center;
  overflow: hidden;
}
.grow:hover {
  height: 145px;
}
<div class="grow" style="background-color: #2a75a9;">
  <h2>Title</h2> 
  <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature</p>
</div>
like image 88
Weafs.py Avatar answered Oct 06 '22 23:10

Weafs.py


just update;

.grow:hover {
    height: auto; /* This is the height on hover */
}
like image 45
Aru Avatar answered Oct 06 '22 22:10

Aru