css - Bootstrap - 如何将 div 从右上左下居中?

标签 css responsive-images

使用 Bootstrap - 如何使 div 从右、左、上和下居中,并使图片响应? 我试过这个:

#logo{
    position:absolute;
    top: 50%;
    left: 50%;
    width:500px;
    height:200px;
    margin-top: -100px; /*set to a negative number 1/2 of your height*/
    margin-left: -250px; /*set to a negative number 1/2 of your width*/
} 

但是它禁用了 img-responsive。 有什么解决方案可以使它们都起作用吗?

最佳答案

解决方法

#logo{
    position:absolute;
    top:50%;
    left: 50%;
    width: 100%;
    height: auto;
    max-width: 500px;
    transform: translate(-50%,-50%);
}

关于css - Bootstrap - 如何将 div 从右上左下居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33224916/

相关文章:

javascript - 防止在滚动模态框内容时滚动背景 div

html - 如何为 link/div 背景添加 css 过渡颜色更改

html - 将图片放在 Angular 落,将文字放在中间

css - 单行 div 内不成比例的流体图像缩放

css - Bootstrap 在 Safari 中无响应 - 主机 : Google Drive

css - 为什么 max-width 将图像限制为其原始分辨率而不是包含 block 宽度?

html - 带有叠加文本的响应图像保持在同一位置

javascript - Jquery 滑动不工作

javascript - 我想在 td 的值发生变化时更改高亮 td

html - 如何根据屏幕尺寸预加载正确数量的图像?