【问题标题】:image height to full div height when container cant be changed当容器无法更改时,图像高度为完整 div 高度
【发布时间】:2014-03-11 15:22:42
【问题描述】:

我的情况是我无法更改主容器并实现body,html 高度和边距。

我想通过 CSS 设置图像,我希望 DIV 成为图像的全高和全宽。

实现这一点的最佳方法是什么我在谷歌上找到的大多数东西都使用div 然后是img 标签

【问题讨论】:

    标签: html css image height


    【解决方案1】:

    在 div 中使用背景图像并将宽度/高度设置为图像的尺寸。

    使用封面或包含的背景大小值也很容易缩放图像。

    见:http://www.w3schools.com/cssref/css3_pr_background-size.asp

    <div style="background-image:url('image.jpg'); width:100px; height:100px;"></div>
    

    或者使用背景尺寸尺寸

    <div style="background-image:url('image.jpg'); background-size:100px 100px; width:..; height:..;"></div>
    

    【讨论】:

    • 请问能否提供一个js小提琴
    猜你喜欢
    • 2015-01-05
    • 2014-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多