Set a DIV height equal with of another DIV

后端 未结 7 2426
终归单人心
终归单人心 2020-12-08 11:06

I have two DIVs, .sidebar and .content and I want to set .sidebar to keep the same height with the .content.

I\'ve tried the f

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 11:48

    In my experience, it's a very, very bad idea to use Javascript for this sort of thing. The web should be semantic. It isn't always, but it should. Javascript is for interactive functionality. HTML is for content. CSS is for design. You CAN use one for the the other's purpose, but just because you CAN do something doesn't mean you SHOULD.

    As for your problem specifically, the short answer is: you don't stretch the sidebar. You don't have to. You set up a background that looks like your sidebar and let it look like a column. It's, as Victor Welling put it, a faux-column.

    Here's one of many web pages that show how to do it:

    http://www.alistapart.com/articles/fauxcolumns/

    But resort it to Javascript for that sort of presentation issue would be "wrong" even if it worked.

提交回复
热议问题