Lately, I've felt like my mind is starting to unravel.
Here's the issue at hand: I've been attempting to resize an image within a table cell so that it spans the full width of the cell. Strangely enough, this seems to be harder than anticipated. Despite my efforts and exhaustive searches online, I haven't found a solution that actually works. I know the theory behind it should, but in practice, not so much.
Let me show you the code:
function scrollElmVert(el,num) { // Use a negative number to scroll up
var re=/html$/i;
while(!re.test(el.tagName) && (1 > el.scrollTop)) el=el.parentNode;
if(0 < el.scrollTop) el.scrollTop += num;
}
var acc = document.getElementsByClassName("accordion");
var i;
var open = null;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
if (open == this) {
open.classList.toggle("active");
open = null;
} else {
if (open != null) {
open.classList.toggle("active");
}
this.classList.toggle("active");
open = this;
// Scroll to clicked element
open.scrollIntoView();
scrollElmVert(open,-68);
}
});
}
.accordion {
background-color: #fff;
color: #444;
cursor: pointer;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
transition: 0.4s;
margin: -5px;
}
/* Code commented out for troubleshooting */
.bg {
width: 100%;
}
.active,
.accordion:hover {
background-color: #fff;
}
.panel {
padding: 0 0px;
display: none;
width: 100%;
background-color: white;
overflow: hidden;
}
.accordion.active+div {
display: block
}
.column {
float: left;
width: 50%;
padding: 10px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
<button class="accordion">
<div class="cat_text">
Cat 2 Placeholder
</div>
</button>
<div class="panel">
<div class="row">
<div class="column" style="background-color:#aaa;text-align:center;position:relative;">
<img src="http://via.placeholder.com/165x555" style ="width:100%">
<p>Some text</p>
<p>Some text..</p>
</div>
<div class="column" style="background-color:#bbb;">
<p>Some text..</p>
<p>Some text..</p>
<p>Some text..</p>
</div>
</div>
<div class="row">
<div class="column" style="background-color:#aaa;">
<p>Some text..</p>
<p>Some text..</p>
<p>Some text..</p>
</div>
<div class="column" style="background-color:#bbb;">
<p>Some text..</p>
<p>Some text..</p>
<p>Some text..</p>
</div>
</div>
</div>
<button class="accordion">
<div class="cat_text">
Cat 3 Placeholder
</div>
</button>
<div class="panel">
<p>Cat 3 Content</p>
</div>
<button class="accordion">
<div class="cat_text">
Cat 4 Placeholder
</div>
</button>
<div class="panel">
<p>Cat 4 Content</p>
</div>
<button class="accordion">
<div class="cat_text">
Cat 5 Placeholder
</div>
</button>
<div class="panel">
<p>Content 5</p>
</div>