php - 盒子相互重叠

标签 php jquery css

所以我有一个 while 循环显示名称和一些 css 和 jquery 来实现它,所以当你将鼠标悬停在 while 循环中制作的其中一个框上时,它会有一些说明向上滚动的结果。但问题是所有描述框都相互重叠。我做错了什么?

CSS

  .App_display { 
        border: 2px solid black; 
    padding:30px; 
    background:white;  
    border-radius:25px;
    float:left;
    width:190px;
    height:100px;
    margin:10px;
 }

.boxTop { position:absolute; z-index:9; top:0; left:0; height:inherit; width:inherit;
          overflow:hidden;}
.description { position:absolute; bottom:-50px; height:40px; width:459px; background-color:#000; opacity:.7; font-size:16px; color:#fff; padding:10px; }

查询

<script>
$('.App_display').hover(function() {
    $(this).find('.description').stop().animate({
        bottom: '0px',
    })
},

function() {
    $(this).find('.description').stop().animate({
        bottom: '-50px',
    })
});
</script>

Html(这段代码是在while循环中生成的)

<div class="App_display">
    <div class="boxTop">
        <div class="description"><?php echo $name; ?></div>
    </div>

</div>

  .App_display { 
        border: 2px solid black; 
    padding:30px; 
    background:white;  
    border-radius:25px;
    float:left;
    width:190px;
    height:100px;
    margin:10px;
 }

.boxTop { position:absolute; z-index:9; top:0; left:0; height:inherit; width:inherit;
          overflow:hidden;}
.description { position:absolute; bottom:-50px; height:40px; width:459px; background-color:#000; opacity:.7; font-size:16px; color:#fff; padding:10px; }
       <div class="App_display">
            <div class="boxTop">
                <div class="description">Item1</div>
            </div>
        </div>
        <div class="App_display">
            <div class="boxTop">
                <div class="description">Item2</div>
            </div>
        </div>


        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <script>
        $('.App_display').hover(function() {
            $(this).find('.description').stop().animate({
                bottom: '0px',
            })
        },

        function() {
            $(this).find('.description').stop().animate({
                bottom: '-50px',
            })
        });
        </script>

最佳答案

在 css 中,当您使用绝对位置时,它将设置元素相对于第一个非静态祖先元素的位置,在您的情况下可能是窗口。 所以你需要将下一个祖先设置为非静态位置然后它会解决你的问题

将这一行添加到您的 App_display 类:

 .App_display { 
        position:relative;
 }

关于php - 盒子相互重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27630070/

相关文章:

jquery - slideToggle 的文本和背景之间的时间滞后

javascript - 如何 "dereference"一个对象?

php - 如何获取 CodeIgniter 4 中的特定列?

javascript - jQuery 点击事件语法

javascript - 使有吸引力的滚动条与所有浏览器兼容

html - CSS在不同屏幕中居中一个div

javascript - 为什么我的 Canvas 不使用 Fabric.js 显示任何内容?

php - JSON_decode数组插入mysql表

php - PayPal 沙箱 IPN 不再响应

jquery - 有一些 'two digit number' <= 'single digit number' jQuery 问题