Reputation: 31
I made a DIVs overflow (with 1/4 of the DIV size) to make a nice effect and gain a little bit of space. However, parent DIV is still same width when the DIVs were next to eachother.
When I try to make parent DIV smaller, last picture is moved to 2nd line.
Is there a way I could make parent DIV smaller to match the images when they are placed onto eachother? As pictures are 24x24px, they should take maximum of 78px instead of 96px (on JSbin it somehow got blank spaces in between of images, so it is wider than it should).
CODE
#assignee-img-container {
display: inline-block;
float: left;
margin: px auto 0px auto;
line-height: normal;
width: 108px;
border: 1px solid black;
height: 24px;
}
.assignee-img {
position: relative;
display: inline-block;
overflow: visible;
border-radius: 50%;
height: 24px;
width: 24px;
border: none;
}
<div id="assignee-img-container">
<div class="assignee-img" style="z-index: 10; left: 0px;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 11; left: -8px;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 12; left: -16px;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 13; left: -24px;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
</div>
<div id="assignee-img-container">
<div class="assignee-img" style="z-index: 10; left: 0px;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 11; left: 0px;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 12; left: 0px;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 13; left: 0px;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
</div>
Upvotes: 0
Views: 38
Reputation: 106
The problem was in using that left for positioning, as it can mess the flow of container. Here I removed that and instead of inline-block
used inline-flex
and justify-content: center
.
Here is the HTML:
<div id="assignee-img-container">
<div class="assignee-img" style="z-index: 10;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 11;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 12;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 13;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
</div><div id="assignee-img-container">
<div class="assignee-img" style="z-index: 10;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 11;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 12;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
<div class="assignee-img" style="z-index: 13;">
<img src="https://static.neris-assets.com/images/test-header-3.svg">
</div>
</div>
And the CSS:
#assignee-img-container {
display: inline-flex;
margin: px auto 0px auto;
line-height: normal;
width: 108px;
border: 1px solid black;
height: 24px;
}
.assignee-img {
position: relative;
display: inline-flex;
justify-content: center;
overflow: visible;
border-radius: 50%;
height: 24px;
width: 24px;
border: none;
}
Upvotes: 1
Reputation: 9787
The problem is that when you use e.g. left: -8px
to shift your elements, it moves the element relative to where it was, but the container behaves as if the element was in its original position - so you still get a reflow if the container is too narrow.
You should look as using display:flex
for this kind of layout. That way you can either have your images together (default) or spread them out automatically using justify-content:space-between
.
Upvotes: 1