html - Make parent div same width as child, and ignore parent -
i have parent, child, , grandchildren divs
. grandchildren need displayed in rows, not columns. i'm trying child have same width grandchildren, (the child's children,) @ same time, want parent retain height of grandchildren.
i tried making child position: absolute
, problem is, parent doesn't retain child, , grandchildren's height.
how can make parent have same height descendants, while having different width. , have child have same width grandchildren?
*, *:before, *:after { margin: 0; padding: 0; box-sizing: border-box; } #wrapper { background-color: lightblue; width: 220px; } #innerwrapper { display: flex; background-color: blueviolet; } .item { background-color: tomato; width: 100px; height: 100px; border: 1px solid blue; margin: 5px; flex: 1 0 auto; } #other { background-color: yellow; width: 300px; height: 250px; }
<div id="wrapper"> <div id="innerwrapper"> <div class="item">item - 1</div> <div class="item">item - 2</div> <div class="item">item - 3</div> <div class="item">item - 4</div> <div class="item">item - 5</div> <div class="item">item - 6</div> </div> </div> <div id="other">i'm element</div>
update
op wanted:
- grandma @ 220px gave
max-width:220px
- mom fitting kids shrink-wrap extending past grandma. gave
position:relative
escape grandma's flow,min-width: 635px
total of kids width margins included,min-height:110px
height of kid plus margins. kids
display: inline-block
,position: absolute
. gave themleft
of interval of accumulative values of 105px usingnth
selector:div div div:nth-of-type(x) { left:105px++ }
see snippet clearer picture.
mom has semi-transparent background can see grandma in black.
#other
given position:relative
, top:110px
move out of way.
i think understand after. in snippet, gave:
1. grandma display:table
, table-layout:fixed
2. mom display:table-row
3. kids display:table-cell
i added dashed border, border-spacing
, , semi-transparent background show presence of grandma , mom. additions optional. removed flexbox properties well.
snippet (revised)
*, *:before, *:after { margin: 0; padding: 0; box-sizing: border-box; } #wrapper { background-color: black; max-width: 220px; float: left; } #innerwrapper { background-color: rgba(0, 0, 200, .5); display: inline-block; position: relative; display: flex; min-width: 635px; min-height: 110px; } .item { background-color: tomato; width: 100px; height: 100px; border: 1px solid blue; margin: 5px; display: inline-block; position: absolute; } div div div:nth-of-type(2) { left: 105px; } div div div:nth-of-type(3) { left: 210px; } div div div:nth-of-type(4) { left: 315px; } div div div:nth-of-type(5) { left: 420px; } div div div:nth-of-type(6) { left: 525px; } #other { background-color: yellow; width: 300px; height: 250px; position: relative; top: 110px; }
<div id="wrapper"> <div id="innerwrapper"> <div class="item">item - 1</div> <div class="item">item - 2</div> <div class="item">item - 3</div> <div class="item">item - 4</div> <div class="item">item - 5</div> <div class="item">item - 6</div> </div> </div> <div id="other">i'm element</div>
Comments
Post a Comment