html - 如何将 Logo 放在背景图像的中心?

标签 html css twitter-bootstrap

我想将 Logo 放在背景图片的中心。我通过添加边距尝试了此操作。但是当我将屏幕调整为小尺寸时,它会产生额外的空间。我认为这不是正确的方法。请帮助我解决这个问题。 problem

HTML:

<div class="details-section section">
        <div class="container-fluid">
            <div class="equal row">
                <div class="big-small">
                    <div class="big col-sm-8">
                        <img src="images/logo.png" alt="Vintage bike" class="img-responsive center-block"/>
                    </div>
                    <div class="small col-sm-4"></div>
                </div>
                <div class="small-big"></div>
                <div class="big-small-big"></div>
            </div>
        </div>
    </div>

CSS:

.details-section .big {
    background: url("images/vintage-bike.jpg") no-repeat 0 0 / cover;
}
.details-section .big img {
    width: 92px;
    margin: 180px auto;
}

我在这里更新这段代码的工作 fiddle 。

Working Demo

最佳答案

第一版:

.details-section .big{
    position: relative;
    background: #f5f5f5;
}
.details-section .big img{
    position: absolute;
    display: block;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
}

第二个版本,它只适用于固定容器高度,但有时有用:

.details-section .big{
    height: 150px; // Change if need
    background: #f5f5f5;
    text-align: center;
}
.details-section .big:after{
    content: "";
    display: inline-block;
    height: 100%;
    vertical-align: middle;
}
.details-section .big img{
    display: inline-block;
    vertical-align: middle;
}

http://jsfiddle.net/7o8bndtv/

关于html - 如何将 Logo 放在背景图像的中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32086632/

相关文章:

html - 为什么这张图片有右边距?

python - 我如何获得一个项目,但前提是该项目是某个标签的同级项目

javascript - 来自用户输入变量的文本不在 div 元素中

JQuery:append 和 appendTo 不起作用?

css - 字体大小相对于父框高度

ruby-on-rails-3 - 找不到或无法读取要导入的文件 : bootstrap-wysihtml5

HTML/CSS 多张图片重叠

html - 为什么我的侧边栏一直向下?

javascript - 如果需要,显示字段

twitter-bootstrap - 使用 ember.js 模板 Bootstrap 弹出框