将此div定位在其容器的中心? [英] Position this div in the center of it's container?

查看:109
本文介绍了将此div定位在其容器的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在尝试解决之前,请仔细阅读我正在处理的约束。

Before you attempt to solve this please carefully read the constraints I'm dealing with.



约束



Constraints


  1. .pictureContainer 需要保留位置:相对(因为我有一个悬停菜单位置绝对相对于它。)

  1. .pictureContainer needs to remain position: relative (because I have a hover menu that positions absolutely relative to it.)

图像可能小于80 %of #slide 在这种情况下,它仍然必须在中心对齐。这是什么翻译?你不能简单地做一个 margin:0 10%,因为是的,这将集中这种特定情况,但不会满足图像小于80%宽度 #slide

The image could be smaller than 80% of #slide in which case it still must align in the center. What this translates to? You can't simply do a margin: 0 10% because yes that would center this specific case, but it will not satisfy the case where the image is smaller than 80% of the width of #slide





b


$ b你好,我是inline-block元素,位于另一个内联块元素旁边,是不是很精彩?我认为这是美好的!


Hello, I am inline-block element that is positioned beside another inline block element, isn't that wonderful? I think that is wonderful!


推荐答案

不是简单添加:

text-align: center;

到pictureContainer css声明。它会将其中的任何图片。

to pictureContainer css declaration. It will center any image in it.

这篇关于将此div定位在其容器的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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