Div height 100% and expands to fit content

后端 未结 15 960
攒了一身酷
攒了一身酷 2020-11-29 15:51

I have a div element on my page with its height set to 100%. The height of the body is also set to 100%. The inner div has a background and all that and is different from t

15条回答
  •  野性不改
    2020-11-29 16:32

    Usually this problem arises when the Child elements of a Parent Div are floated. Here is the Latest Solution of the problem:

    In your CSS file write the following class called .clearfix along with the pseudo selector :after

    .clearfix:after {
    content: "";
    display: table;
    clear: both;
    }
    

    Then, in your HTML, add the .clearfix class to your parent Div. For example:

    It should work always. You can call the class name as .group instead of .clearfix , as it will make the code more semantic. Note that, it is Not necessary to add the dot or even a space in the value of Content between the double quotation "". Also, overflow: auto; might solve the problem but it causes other problems like showing the scroll-bar and is not recommended.

    Source: Blog of Lisa Catalano and Chris Coyier

提交回复
热议问题