简体   繁体   English

如何在LI内强制DIV(具有溢出隐藏样式)仍然显示

[英]How to force DIV inside an LI (with overflow hidden styling) still show

I've got 3 LI with class=box and they are styled with overflow hidden. 我有3个带有class = box的LI,它们的样式是隐藏溢出的。 I need to create a DIV with class=badge inside one box (in this case the 3rd/blue box). 我需要在一个框内创建一个带有class = badge的DIV(在本例中是第3个/蓝色框)。

My objective is: 我的目标是:
1. that this badge DIV (set as position absolute) follows or can use as reference the relative position of that particular box. 1.该徽章DIV(设置为绝对位置)遵循或可以用作该特定框的相对位置作为参考。 2. that this yellow badge DIV can be displayed outside of the blue box. 2.这个黄色徽章DIV可以显示在蓝框之外。

I have been trying a lot of things to make this mission impossible code, but I was wondering if anybody here has already done this before. 我一直在尝试很多事情来完成这个任务不可能的代码,但我想知道这里是否有人已经这样做了。

Preferred solution: Javascript or jQuery and workable in IE8 if possible if not at least IE9. 首选解决方案:Javascript或jQuery,如果可能的话,在IE8中可行,如果不是至少IE9。

HTML: HTML:

<div class="container">
    <li class="box" style="background-color: red;">
        red
    </li>
    <li class="box" style="background-color: green;">
        green
    </li>
    <li class="box" style="background-color: blue;">
        <div style="background-color: #ff0;" class="badge">badge</div>
        blue
    </li>
</div>

css: CSS:

.container {
    border:1px solid black;
    width: 500px;
    height: 120px;
    margin: 20px auto 0px;
    background-color: grey;
}
.badge {
    position: absolute;
    width:100px;
    height: 100px;
    border: 1px solid black;
    text-align: center;
    vertical-align: middle;
    bottom: -55px;
}
.box {
    float: left;
    width:100px;
    height: 100px;
    border: 1px solid black;
    margin: 10px; 5px;
    text-align: center;
    vertical-align: middle;
    position: relative;
    /*overflow: hidden;*/
}

NOTE: overflow hidden code is commented, for you to see the output I need to have. 注意:溢出隐藏代码被注释,以便您查看我需要的输出。

I have a jsfiddle here for quick reference: 我在这里有一个jsfiddle以供快速参考:
http://jsfiddle.net/philcyb/1m73qewm/ http://jsfiddle.net/philcyb/1m73qewm/

You could try something like this : 你可以尝试一些像这样的

var $badge = $('div.badge'),
    xOffset = $badge.offset();
$badge.appendTo('body').css({
    top: xOffset.top,
    left: xOffset.left
});

You probably need to add scrollTop() and the like too. 您可能还需要添加scrollTop()等。

So the simplest solution that is supported by what you require would be to add another parent that does your clipping for you. 因此,您需要的最简单的解决方案是添加另一个为您剪辑的父级。

Simple have the structure such as .box > .box-inner > text + badge 简单的有.box > .box-inner > text + badge

An example of how that would look for your blue box would be. 一个如何寻找你的蓝盒子的例子。

<li class="box" style="background-color: blue;">
    <div class="box-inner">
        Blue
    </div>
    <div style="background-color: #ff0;" class="badge">badge</div>
</li>

The CSS for the inner box would be 内盒的CSS将是

.box-inner {
   width:100%;
   height:100%;
   overflow:hidden;
}

I have updated your fiddle with what that would look like. 我已经更新了你的小提琴,看起来像什么。

FIDDLE http://jsfiddle.net/1m73qewm/12/ FIDDLE http://jsfiddle.net/1m73qewm/12/

HTML: HTML:

<li class="box" style="background-color: blue;">
    <div style="background-color: #ff0;" class="box">badge</div>
    blue
</li>

CSS: CSS:

.box {
    float: left;
    width:100px;
    height: 100px;
    border: 1px solid black;
    margin: 10px; 5px;
    text-align: center;
    vertical-align: middle;
    position: relative;
    overflow: hidden;
}

I presume this is what you mean't ! 我认为这就是你的意思! Just see the changes in the above code. 只需查看上面代码中的更改即可。

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

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