search

Home  >  Q&A  >  body text

css - div设置float:left后高度设置自动会无效 ?

.main_box_rightbox {
    width: 950px;
    height: auto;
    float: left;
    margin-left: 5px;
    margin-top: 3px;
    position: relative;
}

这样之后mainboxrightbox 高度只有16px
这是为什么??
有内容!!

高洛峰高洛峰2778 days ago541

reply all(4)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 11:22:58

    Floats not cleared?

    .clear{clear:both;}

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 11:22:58

    I can’t see all your code. I estimate the possible reasons:
    1. The float is not cleared, causing the height to not be expanded.
    2. The content is empty, causing the height to not be expanded. height:auto Automatically adjust the height based on the content within the block.

    reply
    0
  • 迷茫

    迷茫2017-04-17 11:22:58

    Actually. You can set it in the parent p.
    :
    p {

    overfloat: hidden;

    }

    That’s it. No need to use clear floats.

    reply
    0
  • PHPz

    PHPz2017-04-17 11:22:58

    Because you set position:relative, if the child element is positioned in absolute position, it will not be able to open the parent p

    reply
    0
  • Cancelreply