If you use CSS Flexbox Layout, you can do with simple styles. In this example, if one or two side columns are excluded from the layout, the central column will occupy all the remaining width:
<div class="l-middle">
<aside class="l-sidebar l-sidebar-first">
<!-- content -->
</aside>
<main class="l-content" role="main" aria-label="Main content">
<!-- content -->
</main>
<aside class="l-sidebar l-sidebar-second">
<!-- content -->
</aside>
</div>
.l-middle {
display: flex;
flex-wrap: wrap;
}
.l-content {
width: 50%;
flex-grow: 1;
padding: 0 1rem;
}
.l-sidebar {
width: 25%;
padding: 0 1rem;
}
@media screen and (max-width: 768px) {
.l-content, .l-sidebar {
width: 100%;
}
}
This will work correctly if there are conditions in the Layout for hiding empty side columns (not difficult to add yourself):
<?php if (!empty($content['sidebar1'])): ?>
<aside class="l-sidebar l-sidebar-first">
<?php print $content['sidebar1']; ?>
</aside>
<?php endif; ?>
Have you looked at this contrib layout. I believe this is supposed to solve the problem.
https://backdropcms.org/project/harris_flexible
"This layout is similar to Harris layout with collapsing sidebars. If there is no content in any of the sidebars, the main content region will expand to full width."