0

Si tengo lo siguiente:

#t {width:300px;height:300px;background-color:dimgray;border-radius:150px;z-index:1;}

#ticket{
height:100px;
top: 35%;
position: relative;
background-color:white;
width:300px;
z-index:2;
}
<div id="t">
<div id="ticket"></div>
</div>

El div t contiene al div ticket, entonces ¿cómo podría hacer para que el div hijo ticket, herede su width, sin js?

1

3 respuestas 3

3

El width del hijo debe de ser 100% para que siempre tome el ancho del padre

#t {width:200px;height:200px;background-color:dimgray;border-radius:150px;z-index:1;}

#ticket{
height:100px;
top: 35%;
position: relative;
background-color:white;
width:100%;
z-index:2;
}
<div id="t">
<div id="ticket"></div>
</div>

1

Buenos días amigo puedes usar la propiedad inherit en el estilo aplicado

#t {width:300px;height:300px;background-color:dimgray;border-radius:150px;z-index:1;}

#ticket{
height:100px;
top: 35%;
position: relative;
background-color:white;
width:inherit;
z-index:2;
}
<div id="t">
<div id="ticket"></div>
</div>

2
  • Que es inherit?
    – ESCM
    el 13 sep. 2017 a las 14:06
  • inherit es un valor que puedes pasar a la propiedad width para que herede el valor del padre lo puedes usar en todas las propiedades como backgroundcolor etc en este caso heredara el ancho del padre el 13 sep. 2017 a las 14:27
0

Solo con darle un width:100% al elemento hijo se redimensionará siempre al tamaño que tenga su elemento padre. Saludos.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.