2016年2月26日 星期五

父元素hover時變更子元素背景顏色 child element color change when hovering over parent


常常在滑入parent element時,需要去修改child element的color或屬性,在child element沒有設定時,是不需要特別去處理的,當有設定時,可以在hover後加上元素的設定即可。

SASS:
  parent:hover
    background-color: $color-primary !important
    color: $color-font-hover !important
    h3 //child
      color: $color-font-hover !important //key point


Before:
    .parent .child:hover {
         background-color: #00aba7;
         color: #fff;
    }

After:
    .parent:hover .child {
         background-color: #00aba7;
         color: #fff;
    }


附上範例:child element color change when hovering over parent

熱門文章