Make Parent Div Same Width As Child, And Ignore Parent
Solution 1:
UPDATE
OP wanted:
- grandma at 220px so I gave her
max-width:220px - mom fitting kids like shrink-wrap extending past grandma. I gave her
position:relativeto escape grandma's flow,min-width: 635pxwhich is a total of the kids width with margins included,min-height:110pxwhich is the height of a kid plus margins. kids
display: inline-block,position: absolute. I then gave them aleftof an interval of accumulative values of 105px using thisnthselector:divdivdiv:nth-of-type(X) { left:105px++ }See Snippet for a clearer picture.
Mom has a semi-transparent background so you can see grandma in black.
#other was given position:relative and top:110px to move it out of the way.
I think I understand what you are after. In this Snippet, I gave:
1. grandma display:table and table-layout:fixed2. mom display:table-row3. kids display:table-cell
I added a dashed border, border-spacing, and a semi-transparent background to show the presence of grandma and mom. Those additions are optional. I removed the flexbox properties as 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;
}
divdivdiv:nth-of-type(2) {
left: 105px;
}
divdivdiv:nth-of-type(3) {
left: 210px;
}
divdivdiv:nth-of-type(4) {
left: 315px;
}
divdivdiv:nth-of-type(5) {
left: 420px;
}
divdivdiv:nth-of-type(6) {
left: 525px;
}
#other {
background-color: yellow;
width: 300px;
height: 250px;
position: relative;
top: 110px;
}<divid="wrapper"><divid="innerWrapper"><divclass="item">Item - 1</div><divclass="item">Item - 2</div><divclass="item">Item - 3</div><divclass="item">Item - 4</div><divclass="item">Item - 5</div><divclass="item">Item - 6</div></div></div><divid="other">I'm another element</div>Solution 2:
Remove the flux-box from your style and remove the width in your child. I have added the demo here
Post a Comment for "Make Parent Div Same Width As Child, And Ignore Parent"