2014-01-22 33 views
1

我的问题很简单,但我仍然找不到这个答案...Html - 容器中的图像高度(百分比)

假设我们有两个包含Image的容器。

<div id="containera"> 
<div id="containerb"> 
<img id="imagea" src="image.jpg"/> 

</div></div> 

,我们有类似

#containera { width: 50%; height: 50%; background-color:blue;} 
#containerb { width: 80%; height: 80%; background-color:red;} 
#imagea { height:100%; width:auto;} 

问题是:像高为FULL屏幕的高度和不是100%containerb(50%screenheight的80%)。

我希望图像是100%的containerb高度,而不是100%的屏幕高度。 奇怪:如果我使用“宽度”,宽度根据containerb的宽度缩放。

我可以以某种方式限制容器的高度,使它们不会将图像缩放到100%screenheight?试图最大高度以吨计的变化,但它并没有以任何方式工作...

谢谢,如果您有任何想法如何,我可以解决这个..

+1

也许与此相关http://stackoverflow.com/questions/3098842/height-in-percentage-problem-in-html?rq=1? – opalenzuela

+1

http://www.jsfiddle.net请让小提琴演示你的问题。 – zsaat14

+0

是否将img作为#containerb的一个选项放置?因为那你可以看看背景大小的属性。 – ravb79

回答