2010-11-02 26 views
13

que tiene la siguiente DIValtura dinámica para DIV

<div id="products"> 

</div> 

#products 
{ 
    height: 102px; width: 84%; 
    padding:5px; margin-bottom:8px; 
    border: 1px solid #EFEFEF; 
} 

Ahora dentro del DIV, estoy generando dinámicamente 4 enlaces. Pero a veces puede haber más o menos de 4 enlaces. ¿Cómo puedo cambiar la CSS para cambiar dinámicamente el tamaño del DIV de acuerdo con su contenido?

Respuesta

30

conjunto height: auto; Si usted quiere tener una altura mínima de X, entonces se puede escribir

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 */ 
1

Debería estar bien para simplemente tomar la propiedad height de la CSS.

1

Establecer tanto a auto:

height: auto; 
width: auto; 

Por lo que es:

#products 
{ 
    height: auto; 
    width: auto; 
    padding:5px; margin-bottom:8px; 
    border: 1px solid #EFEFEF; 
} 
1

calcular el la altura de cada enlace sin hacer esto

document.getElementById("products").style.height= height_of_each_link* no_of_link 
2

Esto funcionó para mí como-
en 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%); 
    } 

Espero que te ayude también.

Cuestiones relacionadas