Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.