简体   繁体   English

如何在悬停时增加div列的高度以保留其他列的位置?

[英]How to increase the height of column div on hover preserving the position of other columns?

Trying to implement this for 2 days with no luck. 尝试实施2天没有运气。 Here's the thing: there's a typical row with regular columns with additional product class: 事情是这样的:有一个带有常规列的典型行以及其他product类别:

<div class="row">

    <div class="col-lg-4 product">
        // Content
    </div>

    <div class="col-lg-4 product">
        // Content
    </div>

    <div class="col-lg-4 product">
        // Content
    </div>

    .....
</div>

And here's the CSS rule, that changes the height on hover 这是CSS规则,它会更改悬停时的高度

.product:hover {
  height: 500px;
}

What I need is to stay other column divs when a hover is made. 我需要的是在进行悬停时保留其他列div。 It must look like as the following: 它必须如下所示:

在此处输入图片说明

However it renders as (below div columns go down due to "height overload"): 但是,它呈现为(由于“高度超载”而导致div列下降):

在此处输入图片说明

So I've tried several options: 因此,我尝试了几种选择:

  • Giving product class absolute position 赋予product类别absolute位置
  • Giving product class relative position 提供product类别的relative位置
  • Tried to wrap inner content in another product-wrapper div giving absolute|relative position types. 尝试将内部内容product-wrapper在另一个提供absolute|relative位置类型的product-wrapper div中。

None of this worked. 这些都不起作用。

Is it possible to achieve that within bootsrap row columns? 是否可以在bootsrap row实现这一目标? And if so, then how? 如果是这样,那又如何?

Wrap the product div in a new div with position: relative . 将产品div包裹在新的div中, position: relative Then set the product div to position:absolute and use Z-index to make sure it shows over adjacent divs. 然后将乘积div设置为position:absolute并使用Z-index来确保它显示在相邻的div上。

http://codepen.io/sol_b/pen/VmXbzV http://codepen.io/sol_b/pen/VmXbzV

<div class="row">
    <div class="product-wrap">
        <div class="product"></div> 
    </div>         
    <div class="product-wrap">
        <div class="product"></div> 
    </div>            
    <div class="product-wrap">
        <div class="product"></div> 
    </div>      
  <div class="product-wrap">
        <div class="product"></div> 
    </div>         
    <div class="product-wrap">
        <div class="product"></div> 
    </div>            
    <div class="product-wrap">
        <div class="product"></div> 
    </div>    
  <div class="product-wrap">
        <div class="product"></div> 
    </div>         
    <div class="product-wrap">
        <div class="product"></div> 
    </div>            
    <div class="product-wrap">
        <div class="product"></div> 
    </div>    
</div>


.row{
    position: relative;
    width:550px;
    height:500px;
    margin: 0 auto;
}
.product-wrap{
    position:relative;
    float:left;
    width:150px;
    height:150px;
    margin:10px;
}
.product{    
    background:black;
    position:absolute;
    top:0;
    left:0;
    width:150px;
    height:150px;
  transition: 0.2s;
}
.product:hover{
    z-index:100;
    width: 150px;
    height:200px;
    background: grey;
}

You may use the transform scale property like the exemple below as well: 您也可以像下面的示例一样使用transform scale属性

https://codepen.io/wifeo/pen/qzwkb https://codepen.io/wifeo/pen/qzwkb

<link href='http://fonts.googleapis.com/css?family=Roboto:100,400,300,500,700' rel='stylesheet' type='text/css'>

<div align="center" class="fond">
<div style="width:1000px;">

<div class="style_prevu_kit" style="background-color:#cb2025;"></div>
<div class="style_prevu_kit" style="background-color:#f8b334;"></div>
<div class="style_prevu_kit" style="background-color:#97bf0d;"></div>
<div class="style_prevu_kit" style="background-color:#00a096;"></div>
<div class="style_prevu_kit" style="background-color:#93a6a8;"></div>


<div style=" padding:5px; color:#b5e6e3; font-weight:300; font-size:30px; font-family:'Roboto';padding-top:20px;">CSS <font style="font-weight:400;">HOVER</font></div>
        <a href="http://www.wifeo.com/code" style="text-decoration:none;" target="_blank"><div style="  color:#b5e6e3; font-weight:300; font-size:20px; font-family:'Roboto';">www.wifeo.com/code</div></a>

</div>
</div>

.fond{position:absolute;padding-top:85px;top:0;left:0; right:0;bottom:0;
 background-color:#00506b;}

.style_prevu_kit
{
    display:inline-block;
    border:0;
    width:196px;
    height:210px;
    position: relative;
    -webkit-transition: all 200ms ease-in;
    -webkit-transform: scale(1); 
    -ms-transition: all 200ms ease-in;
    -ms-transform: scale(1); 
    -moz-transition: all 200ms ease-in;
    -moz-transform: scale(1);
    transition: all 200ms ease-in;
    transform: scale(1);   

}
.style_prevu_kit:hover
{
    box-shadow: 0px 0px 150px #000000;
    z-index: 2;
    -webkit-transition: all 200ms ease-in;
    -webkit-transform: scale(1.5);
    -ms-transition: all 200ms ease-in;
    -ms-transform: scale(1.5);   
    -moz-transition: all 200ms ease-in;
    -moz-transform: scale(1.5);
    transition: all 200ms ease-in;
    transform: scale(1.5);
}

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

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