问题描述
有没有任何方法垂直中心一个resposnive img没有知道高度和宽度,并且不使用display:table或position:absolute / relative?
Is there any method for vertically center a resposnive img without know height and width and without using display: table or position: absolute/relative?
具体问题是我使用引导旋转木马,我想要中心img响应在不同的分辨率。所以我不能使用位置属性,因为传送带有这个属性和引导使用显示:表,所以我不能使用这个
The specific problem is that I am using bootstrap carousel and I want to center img responsive in different resolutions. So I can't use position attribute because the carousel has this attribute and bootstrap use display: table, so I can't use this.
我不知道图像的尺寸,因为有与PHP dinamycally添加
I don't know the dimensions of the image because there are added dinamycally with PHP
我尝试把一个div容器高度固定属性,这部作品在大屏幕很大,但在较小的决议,这是也不好,因为IMG是非常高的。
I try to put a div container with fixed height attribute, this works great in large screens but in smaller resolutions this is not good because the img is very tall.
我该怎么办?
推荐答案
请尝试以下方法图像的CSS添加:
Try adding the following to the CSS of the image:
margin-right:auto;
margin-left:auto;
display:block;
position:relative;
这篇关于中心垂直img响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!