Hi, Yes i would like two boxes per row instead of three, also here is my code for the header issue
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="TShirts.css" rel="stylesheet" type="text/css">
<title>T-Shirts</title>
<style>
h1{
font-family: Cheque;
font-style: normal;
position: absolute;
left:35vw;
font-size: 2vw;
color:white;
text-shadow: 0 8px 10px rgba(0,0,0,0.5);
}
</style>
</head>
<body>
<h1>First Prohibited Apparel</h1>
<div class="product_wrapper">
<?php
while($row = mysqli_fetch_array($result)){
?>
<div class="product" margin="10px">
<div class="product_img">
<img src="https://images.unsplash.com/photo-1456926631375-92c8ce872def">
</div>
<!-- end product image -->
<div class="product_name">
<h3><?php echo $row['Product_Name'] ?></h3>
</div>
<!-- end product name -->
<div class="product_description">
<p><?php echo $row['Product_Description']?></p>
</div>
<!-- end product_description -->
<div class="product_price">
<span><?php echo $row['Product_Price'] ?></span>
</div>
<!-- end product_price -->
</div>
<!-- end product -->
<?php
}
?>
</div>
</body>
</html>
Simple reason why the <h1></h1> is being dragged down when a top margin is appled to the product_wrapper is because you are positioning it absolutely. If there is no reason to do so then dont use position: absolute;
The below code shows 2 products per row example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Expand Div</title>
<style>
* {
box-sizing: border-box;
}
.product_wrapper {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
width: 80%;
margin: 100px auto 0 auto;
}
.product {
width: 48%;
background-color: #f2f2f2;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
transition: width 1s ease;
margin-bottom: 20px;
padding: 30px;
}
@media screen and (max-width: 768px) {
.product {
width: 48%;
}
}
@media screen and (max-width: 480px) {
.product {
width: 100%;
}
}
.product_img {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
.product img {
max-width: 100%;
}
.product_description {
display: none;
}
.expand {
width: 100%;
}
.width50 {
width: 50%!important;
}
.showDescription {
display: block;
}
.border {
border: 2px solid red;
}
.wrap {
flex-wrap: wrap;
}
</style>
</head>
<body>
<h1 style="text-align: center;">Heading</h1>
<div class="product_wrapper">
<div class="product">
<div class="product_img">
<img src="https://images.unsplash.com/photo-1456926631375-92c8ce872def">
</div>
<!-- end product image -->
<div class="product_name">
<h3>Leopard</h3>
</div>
<!-- end product name -->
<div class="product_description">
<p>Leopard on tree branch</p>
</div>
<!-- end product_description -->
<div class="product_price">
<span>Not for sale</span>
</div>
<!-- end product_price -->
</div>
<!-- end product -->
<div class="product">
<div class="product_img">
<img src="https://images.unsplash.com/photo-1444464666168-49d633b86797">
</div>
<!-- end product image -->
<div class="product_name">
<h3>King Fisher</h3>
</div>
<!-- end product name -->
<div class="product_description">
<p>King Fisher perched on branch</p>
</div>
<!-- end product_description -->
<div class="product_price">
<span>Not for sale</span>
</div>
<!-- end product_price -->
</div>
<!-- end product -->
<div class="product">
<div class="product_img">
<img src="https://images.unsplash.com/reserve/wrev1ljvQ6KlfyljCQG0_lion.jpg">
</div>
<!-- end product image -->
<div class="product_name">
<h3>Lion</h3>
</div>
<!-- end product name -->
<div class="product_description">
<p>Roaring lion laying on grass</p>
</div>
<!-- end product_description -->
<div class="product_price">
<span>Not for sale</span>
</div>
<!-- end product_price -->
</div>
<!-- end product -->
</div>
<!-- end product wrapper -->
</body>
<script>
const productWrapper = document.querySelectorAll('.product_wrapper');
const product = document.querySelectorAll('.product');
const productImg = document.querySelectorAll('.product_img');
const productDescription = document.querySelectorAll('.product_description');
function expandDiv() {
product.forEach(function(item, index) {
item.onclick = function() {
product.forEach(function(item, index) {
productImg[index].classList.remove('width50');
productDescription[index].classList.remove('showDescription');
item.classList.remove('expand');
})
productImg[index].classList.add('width50');
productDescription[index].classList.add('showDescription');
item.classList.add('expand');
}
})
}
expandDiv();
window.addEventListener('resize', getWindowWidth);
function getWindowWidth() {
const productWrapper = document.querySelector('.product_wrapper');
const windowWidth = window.innerWidth;
if(windowWidth < 768) {
productWrapper.classList.add('wrap');
product.forEach(function(item, index) {
productImg[index].classList.remove('width50');
productDescription[index].classList.remove('showDescription');
item.classList.remove('expand');
})
product.forEach(function(item, index) {
item.onclick = function() {
product.forEach(function(item, index) {
productDescription[index].classList.remove('showDescription');
})
productDescription[index].classList.add('showDescription');
}
})
}
else {
productWrapper.classList.remove('wrap');
expandDiv();
}
}
</script>
</body>
</html>