Need CSS sidebar height to expand with content

前端 未结 8 1221
情深已故
情深已故 2021-01-07 00:20

I have a two column layout, with a gray sidebar on the right. I need the sidebar\'s height to expand when the height of the left column is increased (due to content being dy

8条回答
  •  太阳男子
    2021-01-07 00:44

    I have been haunted by this problem for a while and I wrote an article about this issue: Done with faux columns. Here is what I argued:

    JavaScript based solution for this problem is not worse than any other solution. In fact if you are using JavaScript, you may save a few hours of frustration of trying to get things working. People will warn you against this by saying “What will happen if the user turned off JavaScript?“. Believe me, if the user has turned off JavaScript, most of the web is broken for him anyway. Your sidebar does not matter to him.

    As cballou mentioned, the simplest way to do this thing is to use JQuery code:

    $(".sidebar").height(Math.max($(".content").height(),$(".sidebar").height()));
    

提交回复
热议问题