Is there a way to make #leftdiv
expand to 100% when #rightdiv
is hidden, and have both <div>
s positioned next to each other when a button is clicked?
I have successfully aligned both <div>
s next to each other upon button click, but I would like #leftdiv
to occupy 100% width when #rightdiv
is invisible.
function toggleSideBar() {
var div = document.getElementById('rightdiv');
if (div.style.display !== 'none') {
div.style.display = 'none';
} else {
div.style.display = 'block';
}
};
#leftdiv
{
border: solid medium thick;
float: left;
display: inline-block;
background-color: #ffc;
/*border: 1px solid red;*/
}
#rightdiv
{
width: 50%;
border: solid medium thick;
background-color: #ffa;
display: none;
float:right;
}
<input type="button" id="btn" value="toggle" onclick="toggleSideBar()" />
<div id="main-content">
<div id="leftdiv">selectable</div>
<div id="rightdiv">right panel</div>
</div>`