【发布时间】:2016-04-02 17:33:57
【问题描述】:
我有一个有两个孩子(部分)的进度条。每当这些子项中的每一个悬停时,进度及其子项的总高度都会发生变化。我已经设法使用next sibling selector 解决了第一个孩子的问题,但我找不到第二个孩子的解决方案(黄色部分)。到目前为止,我已经使用 jQuery 解决了这个问题,但我想用纯 CSS 来解决这个问题。
小提琴:https://jsfiddle.net/zfh263r6/5/
$('#start').on({
mouseenter: function () {
//$(this).css('height', '4px');
//$( 'progress' ).css('height', '4px');
},
mouseleave: function () {
//$(this).css('height', '');
// $( 'progress' ).css('height', '');
}
});
#progress_wrap {
position: relative;
height: 4px; /*max height of progress*/
background: #f3f3f3;
}
progress {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
width: 100%;
border:none;
height: 2px;
transition:all .25s ease-in;
cursor: pointer;
background-color: #fff;
position: absolute;
top: 0;
left: 0;
display: block;
}
progress:hover, progress:hover + #start {height: 4px}
progress[value] {
/* Reset the default appearance */
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
/* Get rid of default border in Firefox. */
border: none;
/* For IE10 */
color: #f8008c;
}
progress[value]::-webkit-progress-bar {
background-color: #fff;
border:none;
}
progress[value]::-webkit-progress-value {background:#f8008c}
progress::-ms-progress-value {background:#f8008c}
progress::-moz-progress-bar {background:#f8008c}
progress::-ms-fill {border: none}
#start {
height: 2px;
transition: all .25s ease-in;
cursor: pointer;
background-color: #ffe232;
position: absolute;
top: 0;
left: 0px;
width: 30px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="progress_wrap">
<progress min="0" max="1" value="0.66" id="progress"></progress>
<div id="start" style="display: inline-block; left: 50px;"></div>
</div>
【问题讨论】:
-
CSS 不能选择以前的兄弟姐妹。
-
有没有其他方法可以仅使用 CSS 来实现这一点? @Vohuman
-
我不这么认为。我唯一能想到的就是将
progress和start设置为悬停高度,然后使progress_wrapoverflow:hidden 更短,并使that 在悬停时扩展。 -
嘿,这太酷了。它的工作原理谢谢。 @Draco18s
-
唯一的问题是它将我的其他元素向下推:/
标签: javascript jquery html css