In a grid layout created with CSS, the fourth member in every row appears to be misaligned

I have 16 boxes, and they are divided into 4 groups.

There is an alignment issue in my code where the 4th member of each row drops down to the next line.

I am looking to keep the 4 groups of boxes in a single row without any of them dropping down to the next line.

How can I fix this and ensure the 4 groups stay in a single line?

How can I correct this issue and keep the 4 groups in a single line?

.box {
  width: calc(33.3% - 9px);
  border-radius: 5px;
  border:2px solid white;
  
  
  margin: -2px;
  background-color: #666666;

  height: 10vh;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  
  background-repeat:no-repeat;
  background-size: cover;
  cursor:pointer;
}

#container {
    white-space:nowrap;
border:px solid #CC0000;

}

.containerr{
border:px solid #FF3399;
} 
.pic{
background-size: 100% 100%;
}

.container2 {
  width: 29.0vw;
  position: fixed;
  top: 0.9vh;
  left: 19.2vw;
}
.box p {
 font-size: calc(2vw + 10px);
}
p{
font: "Courier New", Courier, monospace;
font-size:15px;

 color: rgba(0,0,0,0.6);
text-shadow: 2px 8px 6px rgba(0,0,0,0.2),
                 0px -5px 35px rgba(255,255,255,0.3);

color: #005ce6;
text-align: center;
}
<div class="container2">
      <div class="containerr">
        <div class="pic" id="content">


           <div id="container">
            
                <div class="box"  id="1"><p name="values">1</p></div>
                <div class="box"  id="2"><p name="values">2</p></div>
                <div class="box"  id="3"><p name="values">3</p></div>
                <div class="box"  id="4"><p name="values">4</p></div>
            </div>
             <div id="2container">
            
                <div class="box"  id="5"><p name="values">5</p></div>
                <div class="box"  id="6"><p name="values">6</p></div>
                <div class="box"  id="7"><p name="values">7</p></div>
                <div class="box"  id="8"><p name="values">8</p></div>
            </div>
            <div id="3container">
            
                <div class="box"  id="9"><p name="values">9</p></div>
                <div class="box"  id="10"><p name="values">10</p></div>
                <div class="box"  id="11"><p name="values">11</p></div>
                <div class="box"  id="12"><p name="values">12</p></div>
            </div>
            <div id="4container">
            
                <div class="box"  id="13"><p name="values">13</p></div>
                <div class="box"  id="14"><p name="values">14</p></div>
                <div class="box"  id="15"><p name="values">15</p></div>
                <div class="box"  id="16"><p name="values">16</p></div>
            </div>
             
        </div>
      </div>
    </div>

Answer №1

Utilizing display:flex; for a responsive layout

.container{
  display: flex;
   white-space:nowrap;
border:1px solid #CC0000;
}

.box {
  width: calc(33.3% - 9px);
  border-radius: 5px;
  border:2px solid white;
  
  
  margin: -2px;
  background-color: #666666;

  height: auto;
  
  align-items: center;
  justify-content: center;
  
  background-repeat:no-repeat;
  background-size: cover;
  cursor:pointer;
}

.pic{
background-size: 100% 100%;
}

.container2 {
  width: 29.0vw;
  position: fixed;
  top: 0.9vh;
  left: 19.2vw;
}
.box p {
 font-size: calc(2vw + 10px);
}
p{
font: "Courier New", Courier, monospace;
font-size:15px;

 color: rgba(0,0,0,0.6);
text-shadow: 2px 8px 6px rgba(0,0,0,0.2),
                 0px -5px 35px rgba(255,255,255,0.3);

color: #005ce6;
text-align: center;
}
<div class="container2">
      <div class="containerr">
        <div class="pic" id="content">


           <div class="container">
            
                <div class="box"  id="1"><p name="values">1</p></div>
                <div class="box"  id="2"><p name="values">2</p></div>
                <div class="box"  id="3"><p name="values">3</p></div>
                <div class="box"  id="4"><p name="values">4</p></div>
            </div>
             <div class="container">
            
                <div class="box"  id="5"><p name="values">5</p></div>
                <div class="box"  id="6"><p name="values">6</p></div>
                <div class="box"  id="7"><p name="values">7</p></div>
                <div class="box"  id="8"><p name="values">8</p></div>
            </div>
            <div class="container">
            
                <div class="box"  id="9"><p name="values">9</p></div>
                <div class="box"  id="10"><p name="values">10</p></div>
                <div class="box"  id="11"><p name="values">11</p></div>
                <div class="box"  id="12"><p name="values">12</p></div>
            </div>
            <div class="container">
            
                <div class="box"  id="13"><p name="values">13</p></div>
                <div class="box"  id="14"><p name="values">14</p></div>
                <div class="box"  id="15"><p name="values">15</p></div>
                <div class="box"  id="16"><p name="values">16</p></div>
            </div>
             
        </div>
      </div>
    </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What alternative can be used for jquery isotope when JavaScript is not enabled?

Is there a backup plan for jQuery isotope if JavaScript isn't working? For instance, if I'm using the fitColumns feature, is there an alternative layout style available in case JavaScript is disabled, similar to what is seen on the new Myspace? ...

Enable a button or class to dynamically alter its color

Hi there! I'm new to coding and just started learning HTML and CSS. My question is: How can I change the color of buttons once they are clicked? <div class="icon-bar"> <a href="#"><i class="fa fa-search" ...

I am seeking to showcase an image in a window, and upon the image being clicked, execute the code in a separate window

I am looking to showcase the image provided below. <img src="http://gfx.myview.com/MyView/skins/livesample/image/livesample.gif" alt="" border="0"><a/> Once the image is clicked, I want it to execute the following code. How can I ensure that ...

Overlay a small image on top of a larger background image using canvas, then merge them into a single set of pixel

Is there a way to combine a smaller image with a larger background image on one canvas while allowing the smaller image to move around? I'll need to save the original background pixel data so that each frame can be redrawn with the overlay in its upda ...

Creative styling options for image thumbnails using Bootstrap

Can someone help me with an issue I'm having while using the Bootstrap Thumbnail grid system? My images are overlapping and I can't figure out why. I've attached an image for reference. Whenever I hover over the images, the ones in the midd ...

Copy the style of a chosen element and apply it to another element

One of the challenges I'm facing involves a dynamic span element that changes based on color selection: <span class="color checked" style="background-color: #ff0000">Red</span> In addition, I have an image element wit ...

incorporating a personalized HTMLElement using Typescript

Hey there! I'm fairly new to using Angular and could use some help. I'm trying to insert a custom HTML element onto a page when a button is clicked, but I'm struggling to figure it out. Here are my HTML and TypeScript files: TypeScript Fil ...

What causes the absence of CSS classes in production while utilizing Tailwind and next.js?

Tailwind version: v9.3.5 PostCSS Configuration: // postcss.config.js module.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, ...(process.env.NODE_ENV === 'production' ? { '@fullhuman/p ...

"Creating dynamic web apps with the powerful duo of Meteor and Zurb

Just starting out with programming and currently working on a new web application using Meteor and AngularJS. I would like to incorporate the elements/css from 'Zurb Foundation For Apps' into my project... I am familiar with including Bootstrap ...

How can one retrieve elements from a loaded webpage?

I've been using the jQuery function .load() to load a page and I'm trying to find a way to access HTML elements within the loaded page from the source page once it's finished loading. The only method I've come across so far is to add pa ...

Tracking progress with a dynamic bar from the beginning to the end

Struggling to develop a progress bar that corresponds to project start dates and end dates. With a roster of 100 projects, spanning from mid-2017 to future launches, the aim is to depict progress between 2018, 2019, and 2020. If a project commenced in 2017 ...

Generate a new nested div if there is already a different child present at the specified coordinates (x, y)

My goal is to add a textarea to a sidebar on the right whenever a click is made on the page. The current code I have is as follows: $('#page_to_be_clicked').click(function(e){ var offset = $(this).offset(); var comment_box_y_coord = e.pa ...

Adding space around images inside a DIV

Hey there! I recently did some work on my website, and now I'm facing a couple of issues. Check out the changes here! After tweaking a few things, the spacing around the images on the index page has gone wonky. I want the padding to be evenly distri ...

Enhance your SVG image in D3 by incorporating a drop-shadow effect

Trying to apply a drop-shadow effect to an SVG image using D3. Check out my code below and see the example block here: var imgurl = 'http://www.logo-designer.co/wp-content/uploads/2015/08/2015-Penn-State-University-logo-design-4.png'; var mar ...

Hiding HTML Labels with Jquery

I have a label that I want to hide initially and then display with the resultant values when the Submit event of the dialog box occurs. The label should not be visible at first, which is correct. However, even after clicking the submit button, it is not sh ...

Change an ASP page into an image format such as JPEG or PNG

Seeking assistance to convert my classic ASP page containing label controls styled with positioning to images in JPG or PNG format, and then send them using CDO. Using Dreamweaver for this task. Any help would be greatly appreciated. ...

Switch the color of the final letter

Sample code snippet: <p class="test">string</p> Looking to dynamically change the color of the last letter, specifically the letter "g", using CSS only, without relying on JavaScript. I am displaying the string character by character and nee ...

"Utilizing ng class with an array of objects: A step-by-step guide

I am facing a scenario in which my response appears as follows: "currency" : [ { "_id" : ObjectId("584aad5d3e2537613e5f4c39"), "name" : "USD" } ], I need to enable my checkbox based on the currency name. I attempted the followi ...

Managing state changes with a slider in ReactJS

I am currently working with the Foundation slider found at this link: click for doc. To access the slider's current value, they recommend using a hidden input like this: <div class="slider" data-slider data-initial-start="50" data-end="200"> & ...

The div height set to 100% and using display:flex is experiencing issues in Chrome

Bootstrap 3.0 is utilized in the design. My goal is to have uniform height for all boxes, with the "more" link on the right box positioned correctly. However, the box ends before reaching the more link. Take a look at this JSFiddle example. Here is the H ...