How can I center the searched images of shows and add spacing below each image? The 12-column grid is not behaving properly and the images are aligned correctly on desktop but not on mobile. Any suggestions on how to fix this using CSS and Bootstrap? The grid seems to be malfunctioning. Can someone please assist me?
const form = document.querySelector('#search-form');
const container = document.querySelector('#container');
form.addEventListener('submit',async function(e){
e.preventDefault();
const searchTerm = form.elements.query.value;
const config = { params: { q:searchTerm}}
const res = await axios.get(`http://api.tvmaze.com/search/shows`,config);
clear();
displayShows(res.data);
form.elements.query.value='';
})
const displayShows = (shows) =>{
for (let res of shows){
if(res.show.image){
const div = addShow(res);
container.appendChild(div);
}
}
}
const addShow = (res) => {
const div=document.createElement('DIV');
const img=document.createElement('IMG');
img.src = res.show.image.medium;
const spanName=document.createElement('P');
spanName.textContent=res.show.name;
div.append(img);
return div;
}
function clear(shows){
container.innerHTML = '';
}
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body{
background-color: #8EC5FC;
background-image: linear-gradient(120deg, #fc8eed 0%, #E0C3FC 50%, #ffffff 100%);
font-family: "Poppins", sans-serif;
min-height: 100vh;
}
header{
font-size: 1.5rem;
color: #960189;;
}
header,form {
min-height: 20vh;
display: flex;
justify-content: center;
align-items: center;
}
form input, form button {
padding: 0.4rem;
font-size: 1.6rem;
border: none;
background: white;
margin-right: 10px;
}
form input{
width: 27%;
border-radius: 10px;
}
form button {
color: white;
background: #e44ad7;
cursor: pointer;
border-radius: 8px;
transition: all 0.3s ease;
}
form button:hover {
background: white;
color: #e44ad7;
}
.container{
margin: 5%;
}
.container div{
display: inline;
padding: 3%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" integrity="sha512-HK5fgLBL+xu6dm/Ii3z4xhlSUyZgTT9tuc/hSrtw6uzJOvgRr2a9jyxxT1ely+B+xFAmJKVSTbpM/CuL7qxO8w==" crossorigin="anonymous" />
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="60020f0f14131412011020554e504e504d0205140153">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<link rel="stylesheet" href="./TV_ShowSearch.css">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<title>TV SHOW SEARCH</title>
</head>
<body>
<header>
<h1>TV SHOW SEARCH</h1>
</header>
<form autocomplete="off" id="search-form">
<input type="text" placeholder="TV Show Title" name="query">
<button id="search-btn">Search</button>
</form>
<div class="container align-items-center" id="container">
</div>
<script src="./TV_ShowSearch.js"></script>
</body>
</html>