2017-05-06 78 views
0

所以我的网站有3个图像跨越整个宽度,每个使用33.33%的宽度和固定的高度(800px)。我想在每个单独的图像上创建淡入淡出效果,但是一旦我将一些div添加到图像的html代码2中,即使我没有添加任何空间,它也会向下移动。有任何想法吗?添加div后图像移出容器

How it should behave

What happens upon adding new divs

这里是没有任何新的div代码,就如何解决这一问题的任何想法?

<div id="content"> 
     <img src="images/phantom.png"alt="An image showing a male actor performing during the musical Phantom of the Opera" class="musicalimage"> 
     <img src="images/lion_king.png" alt="An image showing a male actor performing during the musical Lion King" class="musicalimage"> 
     <img src="images/wicked.png" alt="An image showing a female actor performing during the musical Wicked" class="musicalimage"> 
</div>` 

#content { 
    height: 800px; 
    width: 100%; 
    font-size: 0px; 

} 

.musicalimage { 
    width: 33.33%; 
    height: 800px; 
    display: inline; 

回答

0

只需添加display: flex#content

#content { 
 
    height: 800px; 
 
    width: 100%; 
 
    font-size: 0px; 
 
    display: flex; 
 
} 
 

 
.musicalimage { 
 
    width: 33.33%; 
 
    height: 800px; 
 
    display: inline; 
 
}
<div id="content"> 
 
    <img src="images/phantom.png" alt="An image showing a male actor performing during the musical Phantom of the Opera" class="musicalimage"> 
 
    <img src="images/lion_king.png" alt="An image showing a male actor performing during the musical Lion King" class="musicalimage"> 
 
    <img src="images/wicked.png" alt="An image showing a female actor performing during the musical Wicked" class="musicalimage"> 
 
</div>`

+0

咦所以这一切是...太感谢你了:d ps的。 flex究竟做了什么?我认为内联块会做同样的事情.. – PinkieBarto

+0

只是谷歌的Flexbox,你会很容易地找到相当多的资源 –