I am trying to hide the border of a collapsible drawer when it is closed. Currently, it still shows the border when it is closed, indicated by the line under each drawer selector. How would I go about hiding it?
HTML:
<button type="button" class="collapsible"> Loose Crimp Issue </button>
<div class="content">
<div class="column">
<p>Check that the wires and crimps are fully inserted into J1, J4, and trandsducer connectors.</p>
</div>
<div class="column">
<img src="../images/looseCrimp.png" alt="Picture of Connectors">
</div>
</div>
CSS:
.content {
padding: 0 18px;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
background-color: white;
border: solid 1px #D1D3D4;
border-radius: 3px;
}
.collapsible {
background-color: white;
color: #021032;
cursor: pointer;
padding: 14px;
width: 100%;
border: solid 1px #D1D3D4;
border-radius: 6px;
text-align: left;
outline: none;
font-size: 15px;
margin: 5px 0px;
}
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
});
}
.content {
padding: 0 18px;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
background-color: white;
border: solid 1px #D1D3D4;
border-radius: 3px;
}
.collapsible {
background-color: white;
color: #021032;
cursor: pointer;
padding: 14px;
width: 100%;
border: solid 1px #D1D3D4;
border-radius: 6px;
text-align: left;
outline: none;
font-size: 15px;
margin: 5px 0px;
}
.active, .collapsible:hover {
background-color: #f7f7f7;
}
<button type="button" class="collapsible"> Consult Logs </button>
<div class="content">
<div class="column">
<p>Ensure the disc strength is not at “0”.</p>
</div>
<div class="column">
<img src="../images/discStrength.png" alt="Picture of Logs">
</div>
</div>
I tried to hide and show the border on click. It worked once, then just deleted the border after the first time.
2
Answers
You can add a class to the button when it is clicked (using
onclick
), and use that to modify the CSS for the .collapsible class to remove the border when that class is present. Here’s an (untested) example:HTML:
CSS:
The simplest option is to also set
border-width: 0
and apply a transition to it:Alternatively, move the styling of the card (
border
,border-radius
,padding
, etc.) to a new child inside the element you are going to collapse (the one that gets themax-height
:First solution (set
border-width: 0
) with your original code (without using additional CSS classes):