Using only CSS, show div on hover over

后端 未结 13 1291
时光取名叫无心
时光取名叫无心 2020-11-22 01:58

I would like to show a div when someone hovers over an element, but I would like to do this in CSS and not JavaScript. Do you know how this can be ach

13条回答
  •  没有蜡笔的小新
    2020-11-22 02:23

    The + allow 'select' only first not nested element , the > select nested elements only - the better is to use ~ which allow to select arbitrary element which is child of parent hovered element. Using opacity/width and transition you can provide smooth appear

    div { transition: all 1s }
    .ccc, .ggg { opacity: 0; color: red}
    .ccc { height: 0 }
    
    .aaa:hover ~ .bbb .ccc { opacity: 1; height: 34px }
    .aaa:hover ~ .eee .fff .ggg { opacity: 1 }
    Hover me... to see

    BBBBB
    CCCCC
    DDDDD
    EEEEE
    FFFFF
    GGGGG
    HHHHH

提交回复
热议问题