I have quite a simple bit of CSS formatting - or so I thought!
I have two adjacent elements, the first of which can be hidden. I've used display: none to hide it.
The second element is always present.
I need to maintain a space between the two, so I thought the following bit of CSS would be sufficient:
.hidden + .visible {
margin-left: 200px;
}
However, it seems that although the first element has display: none applied, the selector is still matches the second element as adjacent (not first), so applies the margin.
Aside from finding it quite 'odd', I need to find a way of keeping a space between the two, but only when both are visible.
Any ideas?
There's a snippet attached with an example.
.container {
margin: 50px;
}
.wrapper {
background-color: aqua;
display: flex;
justify-content: flex-start;
}
.item {
background-color: red;
flex: 0 0 auto;
height: 40px;
width: 40px;
}
.hidden {
display: none;
}
.visible {
background-color: lime;
}
.hidden + .visible {
margin-left: 200px;
}
<div class="container">
<div class="wrapper">
<div class="item hidden">hidden</div>
<div class="item visible">visible</div>
</div>
</div>