简体   繁体   English

悬停时div宽度增加(不替换嵌入式div)

[英]div width increase on hover (without displacing inline divs)

Here is the link to my page mintrain.co.uk/indexsp 这是我页面的链接mintrain.co.uk/indexsp

So, for the front-page I have made the four categories have width 25%. 因此,对于首页,我将四个类别的宽度设置为25%。 On top of this, I've made the width double to 50% on hover. 最重要的是,我将悬停时的宽度加倍到50%。 Upon hovering, the div on the far right is pushed below the others. 悬停时,最右边的div被推到其他下方。 How, using css, can I prevent this? 如何使用CSS防止这种情况? I had the idea of making the non-hovered div width decrease (to 16%) but i do not know how to achieve this. 我本来想使非悬停的div宽度减小(到16%),但是我不知道该如何实现。 Any help would be great. 任何帮助都会很棒。

I'd recommend using flexbox . 我建议使用flexbox Just add display: flex to container and flex: 1 to childs to make layout you want. 只需向容器添加display: flex向子级添加flex: 1即可创建所需的布局。 Then add bigger flex value to :hover . 然后将更大的flex值添加到:hover Like this: 像这样:

 .container { display: flex; } .link { flex: 1; /* For demo only */ border: 1px solid #000; height: 40px; transition: 1s all; } .link:hover { flex: 1.5; /* Or any other value */ } 
 <div class="container"> <div class="link"></div> <div class="link"></div> <div class="link"></div> <div class="link"></div> </div> 

For your site, just replace .container with .boxes and .link with #box (which isn't valid HTML on your site, having multiple same IDs) 为您的网站,只需更换.container.boxes.link#box (这是不是在您的网站有效的HTML,有多个相同的ID)

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

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