Vertically center ul in div

前端 未结 5 1027
忘掉有多难
忘掉有多难 2020-12-10 14:22

This is what my code looks like.

5条回答
  •  自闭症患者
    2020-12-10 15:03

    If you can add jQuery library you could try this,

    $(document).ready(function(){
    
        // Remove li float
        $("#container ul li").css("float", "none");
    
        // Get the full height of the UL
        var ulheight = $("#container ul li")[0].scrollHeight;
    
        // Based on the height of the container being 50px you can position the UL accordingly
        var pushdown = (50-ulheight)/2;
        $("#container ul li").css("top", pushdown);
    
    });
    

提交回复
热议问题