Struggling to get CSS working correctly? I'm having an issue with a display panel that shows 1-4 cells with text/image in each row. Everything works fine with at least four cells, but when there are less than 4 (display=none), the cells align to the left and I want them centered.
Here's a visual representation to help understand:
https://i.sstatic.net/yHsW5.jpg
Here is the HTML and CSS I have so far:
HTML:
<!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">
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="OEPanel.js"></script>
<link rel="stylesheet" href="./OEPanel.css">
<title>Document</title>
</head>
<body>
<div id="oepanelcontainer" class="OEContainer clearfix">
<div id="oepanel" class="OEItems clearfix">
<div id="oecell1" class="OECell"></div>
<div id="oecell2" class="OECell"></div>
<div id="oecell3" class="OECell" style="display:none;" ></div>
<div id="oecell4" class="OECell" style="display:none;" ></div>
</div>
</div>
</body>
</html>
CSS:
.OEContainer {
background-color: beige;
min-height: 10em;
vertical-align: middle;
padding: 10px;
max-width:1130px;
margin:auto;
text-align:center;
justify-content:space-between;
}
.OEItems {
min-height: 10em;
vertical-align: middle;
padding: 0px;
max-width:1130px;
margin:auto;
text-align:center;
justify-content:space-between;
}
.clearfix::after { /* clearfix class to expand the element back to its normal height */
content: '';
display: block;
clear: both;
}
.OECell {
background-color: lightblue;
min-height: 10em;
vertical-align: middle;
padding: 0px;
width:250px;
text-align:center;
/* float: left; */
margin: 5px;
}
@media (max-width: 500px) {
.OEContainer {
flex-direction: column;
align-items: center;
}
}
Any assistance is appreciated! Thank you!
IMPORTANT NOTE: I noticed that until a certain width (around 850px), the blocks center properly. However, once the width exceeds this, the blocks suddenly shift to the far left.