CSS - position: absolute; - auto height

后端 未结 8 2030
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 16:46

I am having a problem with some div\'s

The outer div has a min-height, but the inner divs are all varying heights. Because the inner divs are absol

相关标签:
8条回答
  • 2020-12-15 17:20

    I think you should position them relatively and just change "vertical-align" to "top" in the interior divs. Then you won't have the issue of messing with abs divs.

    0 讨论(0)
  • 2020-12-15 17:21

    i've done this task without any JS. Only, by CSS:

    .frame {
       max-height: calc(100vh - 283px); // 283px gives me some space at the botoom of the frame
    }
    
    0 讨论(0)
  • 2020-12-15 17:31

    Maybe u can try max-height: calc(100% - 50%); it will work if the content that should be in the middle of the screen/div is super short/small.

    position:absolute;
    top:0;
    bottom:0;
    margin:auto;
    width:auto;
    height:auto
    max-height: calc(100% - 50%);
    ...etc...
    
    0 讨论(0)
  • 2020-12-15 17:33

    I recently had this problem with a fade in/out CSS transition slideshow, and ended up solving it by giving the first child element position: relative; and the others position: absolute; top:0; left: 0; which ensures that the containers height is the same as the height of first element. Since my CSS transition slideshow uses the opacity property the container dimensions never changes during the course of the slideshow.

    Alas, since I also needed to supply a javascript fallback for older browsers I had to set the container height for these browsers anyway (because of jQuerys fadeIn/fadeOut actually setting display: none; I would guess).

    0 讨论(0)
  • 2020-12-15 17:35

    As far as I know, there's no way for absolutely positioned child elements to affect the height of their statically, or relatively positioned parent elements using only CSS. Either:

    • Reorganize so that the child elements remain in the document flow
    • Use JavaScript on load of the page to set the height of the parent to the height of the largest child

    This issue is common in fade-in/fade-out JavaScript slideshows, and from what I've seen either 1) the height of the parent container needs to be defined or 2) the parent container's height is set dynamically for each slide.

    0 讨论(0)
  • 2020-12-15 17:38

    You can simply float the divs if you want them to be on the same horizontal plane.

    0 讨论(0)
提交回复
热议问题