📌  相关文章
📜  如何使用 CSS 使 div 高度随其内容扩展?

📅  最后修改于: 2022-05-13 01:56:54.025000             🧑  作者: Mango

如何使用 CSS 使 div 高度随其内容扩展?

height 属性用于设置元素的高度。 height 属性不包含元素的内边距、边距和边框。 height 属性包含许多定义元素高度的值。下面列出了 height 属性值:
句法:

height: length|percentage|auto|initial|inherit;

属性值:

  • 高度:自动;它用于将 height 属性设置为其默认值。如果 height 属性设置为 auto 则浏览器计算元素的高度。
  • 高度:长度;用于设置元素的高度,以px、cm等形式设置,长度不能为负数。
  • 高度:初始;它用于将 height 属性设置为其默认值。
  • 身高:继承;它用于从其父元素设置高度属性。

例1:本例使用height:auto;属性来显示内容。

html


     

     
    
    

 

    
          

GeeksforGeeks

          
        

            Also, any geeks can help other geeks by writing             articles on the GeeksforGeeks, publishing articles             follow few steps that are Articles that need             little modification/improvement from reviewers             are published first. To quickly get your articles             reviewed, please refer existing articles, their             formatting style, coding style, and try to make             you are close to them.         

    
      
        

            It is a good platform to learn programming. It             is an educational website. Prepare for the             Recruitment drive of product based companies             like Microsoft, Amazon, Adobe etc with a free             online placement preparation course.         

    
      
        

            The course focuses on various MCQ's & Coding             question likely to be asked in the interviews             & make your upcoming placement season efficient             and successful.         

    
    
 


html


     

     
    
    

 

     
    

GeeksforGeeks

          
        

            Also, any geeks can help other geeks by writing             articles on the GeeksforGeeks, publishing articles             follow few steps that are Articles that need             little modification/improvement from reviewers             are published first. To quickly get your articles             reviewed, please refer existing articles, their             formatting style, coding style, and try to make             you are close to them.         

                  
            

                It is a good platform to learn programming. It                 is an educational website. Prepare for the                 Recruitment drive of product based companies                 like Microsoft, Amazon, Adobe etc with a free                 online placement preparation course.             

        
                  
            

                The course focuses on various MCQ's & Coding                 question likely to be asked in the interviews                 & make your upcoming placement season efficient                 and successful.             

        
    
 


输出

示例 2:本示例使用 height:inherit 属性来显示内容。

html



     

     
    
    

 

     
    

GeeksforGeeks

          
        

            Also, any geeks can help other geeks by writing             articles on the GeeksforGeeks, publishing articles             follow few steps that are Articles that need             little modification/improvement from reviewers             are published first. To quickly get your articles             reviewed, please refer existing articles, their             formatting style, coding style, and try to make             you are close to them.         

                  
            

                It is a good platform to learn programming. It                 is an educational website. Prepare for the                 Recruitment drive of product based companies                 like Microsoft, Amazon, Adobe etc with a free                 online placement preparation course.             

        
                  
            

                The course focuses on various MCQ's & Coding                 question likely to be asked in the interviews                 & make your upcoming placement season efficient                 and successful.             

        
    
                     

输出: