html - 3 个动态内联 div 未固定到位

标签 html css

我正在研究一个简单的 3 div 布局。 div 的宽度均设置为 33.3%,高度设置为 100%。我希望发生的情况是,将鼠标悬停在任何一个 div 上时,该 div 会扩展至 40% 宽度,而另外两个 div 的宽度各减少 3.5%各自的宽度。不幸的是,发生的情况是右侧的 div 下降到下一行。

我非常有信心可以使用 jQuery 轻松完成此操作,但我更喜欢使用纯 css 来完成此操作。

这是代码的 fiddle :

https://jsfiddle.net/99gL47rp/1/

感谢任何帮助! :)

最佳答案

你完全可以做到!你只需要稍微不同地思考一下。 https://jsfiddle.net/jpw4w7ou/ .

/*Use this to give all the child divs the same 33% width */
#sections > div {
    width: 33.3%;
}

/*On hover of the container, drop ALL the children's width to 30% */
#sections:hover > div {
    width: 30%;
    transition:width 0.5s;
}

/*Finally, give the actual child div you are hovering over a width of 40%. This will override the previous selector's 30% width only for the currently hovered element */
#sections > div:hover{
    width: 40%;
    transition:width 0.5s;
}

请注意,我删除了 clear:left,它没有必要,而且会导致问题。

关于html - 3 个动态内联 div 未固定到位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30044550/

相关文章:

html - 将 HTML 表格单元格旋转 180 度

html - 如何使用嵌套 <ul> 设置水平子菜单的样式

html - 将第一个字母定位为外部列表样式

html - 使CSS中具有相同父级的两个div的高度相等

jQuery 使用 animate() 正确反转动画

html - 表头中超链接的 CSS 不适用?

html - CSS 仅针对 IE10 和以下版本(不是 IE11)?

javascript - 输入域字符序列

html - 仅当我在 Chrome 中选择检查元素时,我页面上的 css 菜单栏才有效

html - 子容器与父容器宽度相同