如何设置外部div的高度始终等于特定的内部div?

我有一个外部div,其中包含三个内部div。


我希望最左侧的内部div始终确定外部div的高度。如果其他内部div的内容少于最左边的div,则它们将具有空白空间。如果它们的内容[比最左边的div还要多],它们将获得一个滚动条。


关于SO的其他一些问题询问将外部div的高度设置为内部div 的高度。但是,在我的情况下,我有多个内部div,而外部div的高度不会大于或小于最左侧div的高度。


有什么方法可以做到这一点,尤其是仅使用CSS?

http://img2.mukewang.com/5d8dbc150001771212750775.jpg

炎炎设计
浏览 1122回答 2
2回答

慕工程0101907

不同的方式。两个例子:.outer_div {&nbsp; position: relative;&nbsp; overflow: hidden;&nbsp; max-width: 300px;&nbsp; margin: 0 auto;}.inner_div {&nbsp; width: 33.33%;}.inner_div_1 {&nbsp; float: left;&nbsp; background: khaki;}.inner_div_2,.inner_div_3 {&nbsp; background: darkkhaki;&nbsp; position: absolute;&nbsp; top: 0;&nbsp; height: 100%;&nbsp; overflow-y: auto;}.inner_div_2 {&nbsp; left: 33.33%;}.inner_div_3 {&nbsp; left: 66.66%;}<div class="outer_div">&nbsp; <div class="inner_div inner_div_1">&nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.&nbsp; </div>&nbsp; <div class="inner_div inner_div_2">&nbsp; &nbsp; Lorem ipsum.&nbsp; </div>&nbsp; <div class="inner_div inner_div_3">&nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&nbsp; </div></div>.outer_div {&nbsp; display: flex;&nbsp; flex-direction: row;&nbsp; max-width: 300px;&nbsp; margin: 0 auto;&nbsp; background : gray;}.inner_div {&nbsp; width: 33.33%;}.inner_div > div {&nbsp; position: relative;&nbsp; height: 100%;}.inner_div_1 span {&nbsp; background: khaki;}.inner_div_2 span,.inner_div_3 span {&nbsp; background: darkkhaki;&nbsp; display: block;&nbsp; position: absolute;&nbsp; top: 0;&nbsp; left: 0;&nbsp; width: 100%;&nbsp; height: 100%;&nbsp; overflow-y: auto;&nbsp; overflow-x: hidden;}<div class="outer_div">&nbsp; <div class="inner_div inner_div_1">&nbsp; &nbsp; <span>&nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.&nbsp; &nbsp; </span>&nbsp; </div>&nbsp; <div class="inner_div inner_div_2">&nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; <span>&nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum.&nbsp; &nbsp; &nbsp; </span>&nbsp; &nbsp; </div>&nbsp; </div>&nbsp; <div class="inner_div inner_div_3">&nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; <span>&nbsp; &nbsp; &nbsp; &nbsp; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&nbsp; &nbsp; &nbsp; </span>&nbsp; &nbsp; </div>&nbsp; </div></div>
打开App,查看更多内容
随时随地看视频慕课网APP