If I select multiple images, the div with class “images” overflows, I want it to be scrollable not to overflow and also want to keep the images aspect ratio, how do I do it?
**** Ignore this text, it’s just filler text because StackOverflow says “It looks like your post is mostly code; please add some more details.” ****
**** Ignore this text, it’s just filler text because StackOverflow says “It looks like your post is mostly code; please add some more details.” ****
function init() {
let files = document.querySelector("input[name='files']");
files.onchange = filesChanged;
}
function filesChanged(event) {
let imagesDiv = document.querySelector(".images");
while (imagesDiv.firstChild) imagesDiv.firstChild.remove();
for (let file of this.files) {
let fr = new FileReader();
fr.onloadend = () => {
let img = new Image();
img.title = file.name;
img.src = fr.result;
imagesDiv.appendChild(img);
};
fr.readAsDataURL(file);
}
}
window.addEventListener("load", init);
* {
font-family: inherit;
font-size: inherit;
margin: 0;
padding: 0;
box-sizing: border-box;
word-break: break-word;
}
html,
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 1rem;
width: 100%;
height: 100%;
padding: .25rem;
}
.hide {
display: none !important;
}
.column {
flex: 1;
display: flex;
flex-flow: column;
}
.row {
flex: 1;
display: flex;
flex-flow: row;
}
.gap {
gap: .25rem;
}
input,
textarea {
flex: 1;
border: 1px solid lightgray;
border-radius: .25rem;
padding: .5rem;
}
textarea {
resize: none;
min-height: 10rem;
}
.form {
background-color: bisque;
border: 1px solid lightgray;
border-radius: .25rem;
width: 100%;
max-width: 62.5rem;
}
.form fieldset {
border: none;
padding: .5rem;
}
.form label {
color: gray;
font-size: small;
}
.images {
background-color: gray;
border: 1px solid lightgray;
display: flex;
flex-flow: row;
align-items: start;
overflow-x: auto;
}
.images:empty {
display: none;
}
.images img {
flex: 1;
max-width: 150px;
max-height: 150px;
}
<form action="#" class="form">
<fieldset class="column gap">
<div class="column">
<label>Title</label>
<input type="text" name="title">
</div>
<div class="column">
<label>Details</label>
<textarea name="details"></textarea>
</div>
<div class="column gap">
<input type="file" name="files" multiple accept="image/png, image/jpeg">
<div class="row gap images"></div>
</div>
</fieldset>
</form>


