简体   繁体   English

height =“ 100%”与 <object> 但不是 <img> ,区别HTML vs CSS width / height属性?

[英]height=“100%” works with <object> but not with <img>, difference HTML vs CSS width/height property?

I've got two codes and I don't know why the use of height=100% works only on image? 我有两个代码,但我不知道为什么为什么只在图像上使用height = 100%? in other cases it does nothing and the content choose the minimum height the object ignore it but not the image. 在其他情况下,它不执行任何操作,而内容选择对象忽略它的最小高度,而不是图像。

   <section id="corps">
      <object data="images/test.pdf" type="application/pdf" width="100%" height="100%">

      </object>
      <img src="images/test.png" width="90%" height="90%">
   </section>

And plus, Why width and height property works in html without style = "..." but others like min-height needs it. 另外,为什么width和height属性可以在没有style =“ ...”的html中工作,但是其他类似min-height的东西都需要它。 Is it just because html support these? 仅仅是因为html支持这些吗? Thanks! 谢谢!

<style>
    #corps{ height: Xpx} //replace X with the value that suits you
    #corps object{height: 100%} //Now you'll get the 100% height
</style>

Alternatively, if you use position: absolute then height: 100% will work just fine. 另外,如果您使用position: absolute那么使用height: 100%也可以。

About why <img src="images/test.png" width="90%" height="90%"> works, because height and width are HTML5 properties for images. 关于为什么<img src="images/test.png" width="90%" height="90%">起作用的原因,因为高度和宽度是图像的HTML5属性。 You can achieve the same thing by using <img src="images/test.png" style="width: 90%; height: 90%;"> , Now this is CSS. 您可以使用<img src="images/test.png" style="width: 90%; height: 90%;"> ,现在这是CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM