简体   繁体   English

如何使用Twitter Bootstrap在图像上获取div

[英]How to get divs over an image using Twitter Bootstrap

I'm trying to show an image and divide it using bootstrap div columns , but the image is over the divs , so I can't click or bind jQuery to it. 我正在尝试显示图像并使用bootstrap div columns对其进行划分,但是图像在divs之上,因此我无法click jQuery或将其绑定到它。 Here is my code: 这是我的代码:

#viewer {
    left: 0px;
    position: absolute;
    height: auto;
    margin-top: 16px;
    margin-bottom: 34px;
}

#left {
    cursor: pointer;
    height: auto;
}

#center {
    cursor: pointer;
    height: auto;
}

#right {
    cursor: pointer;
    height: auto;
}

<div class="container">
    <img class="img-responsive" src="wp-content/themes/Cassia/img/back.jpg" id="viewer">
        <div class="row">
            <div id="left" class="col-sm-5 col-md-5 col-lg-5 col-xs-5">
            </div>

            <div id="center" class="col-sm-3 col-md-3 col-lg-3 col-xs-4">
            </div>

            <div id="right" class="col-sm-4 col-md-4 col-lg-4 col-xs-3">
            </div>

        </div>

</div>

What am doing wrong here? 这是怎么了?

To make the image go behind you can add a negative z-index like this: 要使图像落后,您可以添加一个负Z索引,如下所示:

 #viewer { top:0; left: 0; position: absolute; height: auto; margin-top: 16px; margin-bottom: 34px; z-index: -1; } #left { cursor: pointer; height: auto; } #center { cursor: pointer; height: auto; } #right { cursor: pointer; height: auto; } 
 <div class="container"> <img class="img-responsive" src="http://gillespaquette.ca/images/stack-icon.png" id="viewer"> <div class="row"> <div id="left" class="col-sm-5 col-md-5 col-lg-5 col-xs-5">Left </div> <div id="center" class="col-sm-3 col-md-3 col-lg-3 col-xs-4">Center </div> <div id="right" class="col-sm-4 col-md-4 col-lg-4 col-xs-3">Right </div> </div> </div> 

It might be a little tricky, I did it using JS, maybe there is a simpler solution but anyways, I hope this helps: 可能有些棘手,我使用JS完成,也许有一个更简单的解决方案,但是无论如何,我希望这会有所帮助:

JS Fiddle JS小提琴

I added some JS to solve the absolute positioning making parent element have 0 height and thats it. 我添加了一些JS解决绝对定位,使父元素的高度为0,就这样。

$( document ).ready(function() {
    $( ".row" ).each(function() {
        var newHeight = 0, $this = $( this );
        $.each( $this.children(), function() {
            newHeight += $( this ).height();
        });
        $this.height( newHeight );
    });
    $('.row > div').css('height', '100%');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM