CSS how to position an element in a middle (half height / vertical 50%) of another element

后端 未结 4 1671
北荒
北荒 2021-02-08 07:07

I\'m looking forward to build a tooltip which is positioned next to the element, but in a middle of it. It\'s easy to put it over and under and position it in the horizontal cen

4条回答
  •  清酒与你
    2021-02-08 07:43

    using CSS & jQuery-

    CSS

    .div{
        top:50%
    }
    

    jQuery

    var divheight = $(.div).height() / 2;
    $(.div).attr('style','margin-top:-'+divheight+'px;');
    

提交回复
热议问题