【问题标题】:I need to have a img vertical centered in a div, how?我需要一个以 div 为中心的垂直 img,如何?
【发布时间】:2012-11-21 21:19:38
【问题描述】:

供参考:检查: http://jsfiddle.net/blackvibes/mVYwd/

我正在为移动设备创建一个网站(很确定这不是最好的方法......但无论如何)我一直使用百分比,因为它在任何移动设备上的大小都应该相对相等(纵向)屏幕。

我尝试了很多东西,例如:

#header img {
vertical-align:middle;
padding-top: auto;
padding-bottom: auto;
margin-top: auto;
margin-bottom: auto;

}

但我仍然无法让它工作。

该 div 中的唯一内容是显示学校徽标的单个图像。

提前致谢!

【问题讨论】:

    标签: image html vertical-alignment


    【解决方案1】:

    使用您的图片作为#header id 的背景:

    #header img {
        background:url(your_image.jpg) center center no-repeat;
    }
    

    【讨论】:

      【解决方案2】:

      从img标签中删除width和height

      #header{text-align:center;}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-23
        • 2016-06-21
        • 2013-03-11
        • 2010-11-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多