Center vertically img responsive

為{幸葍}努か 提交于 2019-12-12 03:31:53

问题


Is there any method for vertically center a resposnive img without know height and width and without using display: table or position: absolute/relative?

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.

I don't know the dimensions of the image because there are added dinamycally with PHP

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.

How can I do?


回答1:


Try adding the following to the CSS of the image:

margin-right:auto;
margin-left:auto;
display:block;
position:relative;


来源:https://stackoverflow.com/questions/24697400/center-vertically-img-responsive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!