Is there a way to place the content of a container such that it is the second element that appears to be centered, instead of simply centering all children?
So that in my example there would be 30px before the sidebar and 50px after the main-content, instead of having 40px on each side.
I can't just use absolute positioning, as I in the case that the main-content is to large, still want to be able to see the sidebar.
The point is that I have a sidebar, that isn't always visible, and when toggling it on, I do not want it to push the main-content, if there actually is room for it.
class MyComponent extends React.Component {
render() {
return (
<div className="wrapper">
<div className="sidebar" />
<div className="main-content" />
</div>
);
}
}
// Render it
ReactDOM.render(
<MyComponent />,
document.getElementById("root")
);
.wrapper {
background: black;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
height: 200px;
width: 500px;
}
.sidebar {
background: red;
height: 100%;
width: 20px;
flex-shrink: 0;
}
.main-content {
background: blue;
height: 100%;
width: 400px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="root"></div>