How to acquire the width father

0

If I have the following:

#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>

The div t contains the div ticket , so how could I make the div hijo ticket , inherit its width, without js ?

    
asked by Eduardo Sebastian 13.09.2017 в 02:11
source

3 answers

1

Good morning, you can use the inherit property in the applied style

#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>
    
answered by 13.09.2017 / 14:54
source
2

The width of the child must be 100% so that it always takes the width of the father

#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>
    
answered by 13.09.2017 в 04:21
0

Just giving a width:100% to the child element will always be resized to the size of its parent element. Greetings.

    
answered by 13.09.2017 в 15:47