Dynamic height for DIV

后端 未结 6 1659
慢半拍i
慢半拍i 2020-12-28 16:28

I have the following DIV

#products { height: 102px; width: 84%; padding:5px; margin-bottom:8px; border
相关标签:
6条回答
  • 2020-12-28 16:50

    This worked for me as-
    HTML-

        <div style="background-color: #535; width: 100%; height: 80px;">
            <div class="center">
                Test <br>
                kumar adnioas<br>
                sanjay<br>
                1990
            </div>
        </div> 
    

    CSS-

    .center {
        position: relative;
        left: 50%;
        top: 50%;
        height: 82%;
        transform: translate(-50%, -50%);
        transform: -webkit-translate(-50%, -50%);
        transform: -ms-translate(-50%, -50%);
       }  
    

    Hope will help you too.

    0 讨论(0)
  • 2020-12-28 16:52

    set height: auto; If you want to have minimum height to x then you can write

    height:auto;
    min-height:30px;
    height:auto !important;        /* for IE as it does not support min-height */
    height:30px;                   /* for IE as it does not support min-height */
    
    0 讨论(0)
  • 2020-12-28 16:57

    You should be okay to just take the height property out of the CSS.

    0 讨论(0)
  • 2020-12-28 16:57

    calculate the height of each link no do this

    document.getElementById("products").style.height= height_of_each_link* no_of_link
    
    0 讨论(0)
  • 2020-12-28 17:04

    as prior ans remove the height attrib. if u want your expansion along with its min height then use min-height: 102px instead of height: 102px.

    note ie 6 and min-height http://www.dustindiaz.com/min-height-fast-hack/

    0 讨论(0)
  • 2020-12-28 17:07

    Set both to auto:

    height: auto;
    width: auto;
    

    Making it:

    #products
    {
        height: auto;
        width: auto;
        padding:5px; margin-bottom:8px;
        border: 1px solid #EFEFEF;
    }
    
    0 讨论(0)
提交回复
热议问题