Hello, this is my first time posting a question here. I have found many helpful Java answers in this community before, so I thought I'd give it a try. I did some research beforehand, but please let me know if I have duplicated a question or done anything wrong.
My current project involves creating a thumbnails gallery and I have created a jsfiddle link to showcase my progress.
HTML
<body>
<div id="main">
<div id="wrapper">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</div>
</body>
CSS
#main {
background-color: rgba(255, 105, 180, 0.5);
height: 100vh;
padding: 10px;
}
#wrapper {
background-color: blue;
display: inline-block;
padding: 5px;
}
.box {
display: inline-block;
background-color: red;
width: 200px;
height: 200px;
margin: 5px;
}
In the main div, I am attempting to center the red boxes horizontally without using text-align: center;
. I want them to align left-to-right with space between them while keeping the entire block centered. My approach was to use a wrapper div for this purpose. However, I encountered an issue where the blue wrapper extends beyond its content filling the main div.
I came across a solution on StackOverflow that suggests using inline-block
to address this issue, but I am struggling to implement it correctly.
I believe this should be a relatively simple fix, so what am I overlooking?
If you prefer a TLDR version, I have provided some snapshots here.
Thank you in advance!