Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

On :hover, image expands past the div container?

I'm making my first website and I have a few images that increase in scale in hover state. I would also like there to be a box shadow around it. I added the box shadow, but when the image "grows", the shadow extends past the div container. Any ideas how to keep the image and the effects inside the div? Thanks.

<div id="wrapper">
          <div id="container">
              <div id="gallery">
                <figure class="mashedHover">
                <a href="mashed.html"><img src="img/Mashed2.png"><figcaption>Mashed</figcaption></a>
                </figure>

                <figure class="clamHover">
                <a href="clam.html"><img src="img/Sherm2.gif"><figcaption>The Ballad of the<br>Purple Clam</figcaption></a>
                </figure>
                <figure class="timberHover">
                <a href="timber.html"><img src="img/Timber3.jpg"><figcaption>Timber</figcaption></a>
                </figure>
                <figure class="booHover">
                <a href="boo.html"><img src="img/Boo_3.gif"><figcaption>Boo!</figcaption></a>
                </figure> 
               </div> 
          </div>
/******************************************
PAGE: FILMS
*****************************************/
#container, #youtubeEmbed {

  width: 20%; 
  float: left; 
  margin-right: 4%;
  margin-left: auto; 
}

#container {
  background-color:#2d6034;
  width: 200px;   
}

 #gallery {
  /*width: 100%;*/
  margin-top: 1em;
  display: block;
}

#gallery img {
  width: 75%;
  height: auto;
  padding: 5%;
  margin: 0px;
}

 figure {
    text-align: center; 
}

figure a {
  text-decoration:none;
}

figcaption {
  text-align: center;
  color: white;
  font-weight: 800;
  margin-bottom: 14%;
}


.clamHover:hover, .mashedHover:hover, .timberHover:hover, .booHover:hover {
  -webkit-transform: scale(1.1);
  -ms-transform: scale(1.1);
  transform: scale(1.1);
  -moz-box-shadow: inset 0 0 10px #999;
  -webkit-box-shadow: inset 0 0 10px #999;
  box-shadow: inset 0 0 10px #999;
 }

1 Answer

Gurpeer Duhra
Gurpeer Duhra
4,205 Points

Probably because, of not modifying the images size right.

What ever, the hover won't know how big it'll be so it oversize without you telling what size the actual images is.