css水平居中图像 [英] css to center a image horizontally

查看:123
本文介绍了css水平居中图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用css水平居中图片。

I am trying to center a image horizontally using css.

我使用以下HTML代码在屏幕上显示我的图片:

I am displaying my image on the screen with the following HTML code:

<div id="loading" class="loading-invisible">  
    <img class="loading" src="logo.png">
</div>

我裁剪我的图像,因为我只想显示一些图像, css:

I am croping my image as I only want to display some of the image and I am using the following css:

img.loading 
{
position:absolute;
clip:rect(0px,681px,75px,180px);
}

但我无法解决如何将图像

however I can't work out how to center the image once it has been croped.

任何人能帮助?

推荐答案

img.loading{
  position: absolute;
  left: 50%;
  margin-left: -(half ot the image width)px
}

这篇关于css水平居中图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆