Ways to eliminate gaps within CSS flex elements

I need help creating a table structure using CSS flexbox

Check out my CodePen here for reference

I have elements spaced using justify-content: space-between; in a container, but I want to remove the space between the divs so they sit next to each other.

I tried making the cell width 100% but then I lose control over the cells' widths.

*{
  font-family: sans-serif;
}

.content-wrapper,
.content-header{
  display: contents;
}

.content-header{
  .grid-cell{
      font-weight: bold;
    }
}

.grid-wrapper{
  border: 1px solid grey;
}
.grid-cell{
  padding: 5px;
  border: 1px solid lightgrey;
  white-space: no-wrap;
}
.grid-header,
.grid-content{
  display: flex;
  justify-content: space-between;
  //align-content: stretch;
}

.grid-cell-1{
  flex-basis: 80px;
}
.grid-cell-2{
  flex-basis: 68px;
}
.grid-cell-3{

}
.grid-cell-4{
  flex-basis:58px;
}
.grid-cell-5{
  flex-basis: 58px;
}
.grid-cell-6{
  flex-basis: 58px;
}
.grid-cell-7{
  flex-basis: 58px;
}
.grid-cell-8{
  flex-basis: 58px;
}
.grid-cell-9{
  flex-basis: 58px;
}
.grid-cell-10{
  flex-basis: 58px;
}
.grid-cell-11{
  flex-basis: 58px;
}
.grid-cell-12{
  flex-basis: 58px;
}
.grid-cell-13{
  flex-basis: 58px;
}


@media(max-width: 700px){
  .grid-header{
    display: none;
  }

  .grid-content{
    display: initial;
  }

  .grid-cell{
    display: inline;
  }

  .grid-content{
    display: flex;
  }

  .content-wrapper{
    display: initial;
  }

  .content-header{
    display: block;

  }
}

Answer №1

It seems like there may be some confusion regarding your question. However, consider adding a max-width property to your .grid-cell class in order to achieve the desired result.

.grid-cell{
  padding: 5px;
  border: 1px solid lightgrey;
  flex-grow: 1;
  width: 100%;
  max-width: 100px;
} 

To view an example, check out the fiddle here

Keep in mind that for a more responsive approach, transitioning to

display: grid;

may be a better solution. Explore the grid option here

Note: If you require spacing within the grid display, simply add margin to the grid-cells.

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

Ensure that the image's aspect ratio is preserved while adjusting the height of the window on both Safari and Chrome browsers

Trying to style some cards on my website using HTML and CSS, I noticed that the aspect ratio of the cards gets distorted when resizing the window. This issue only seems to happen in Safari, as Chrome handles it fine. I'm not sure which specific comma ...

Incorporate New Material into DIV Using a Specific Class Identifier

I need to customize the default output of Wordpress menu using <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>. My goal is to change the appearance of pages with submenus. Currently, pages with a submenu are fo ...

Navigation through dots on a single page

Having an issue with my dot navigation and anchor links placement. I want the anchors to be vertically centered in the middle of the section, regardless of window size. Here's what I'm aiming for : For larger windows : https://i.sstatic.net/pK4 ...

What is the best way to conceal a `div` containing an error message if there are no errors present?

On this page, you'll find a server-side and client-side validation form. I'm currently using a div id=er> to display error messages when the requirements are not met. However, having the div element always present is causing styling issues for ...

Preventing an error message from taking up space in the DOM when it is not being shown

My Login page features an error message displayed within a div with specific classes. The error message is shown through a <label.../> element. However, upon the initial page load, there is no error message to display, resulting in an empty space wi ...

HTML Techniques: Flipping the Script - Writing Characters from Right to Left

In order to showcase the temperature in degrees Celsius, I have implemented a placement technique using absolute positioning. Consequently, the °C symbol will persist in its designated spot. To achieve the desired presentation, the text should be displaye ...

Incorporating CSS style to individual rows in an HTML table

Is there a way to determine if a specific string, such as 'LA DEFENSE', is present in my HTML table and then change the background color of that line to red? https://i.sstatic.net/Yq7qF.png This is what I am looking for: $("#colorline").click( ...

SASS malfunctioning, error messages popping up in command prompt while running gulp serve

As I develop a web app using AngularJS and Gulp, I encounter an issue where the CSS does not seem to work when running 'gulp serve'. Despite attempting to reinstall various components like node_modules, Node.js, and Gulp, the same error persists. ...

Create a dynamic and adaptable Google Maps experience without the need for an iframe

For instance, if you are using an embedded Google Map. You can ensure that your Google Map is responsive with the following code: Using iframe (simple iframe) <div class="ggmap"> <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m ...

Attempting to conceal image previews while incorporating pagination in Jquery

I'm working on implementing pagination at the bottom of a gallery page, allowing users to navigate between groups of thumbnail images. On this page, users can click on thumbnails on the left to view corresponding slideshows on the right. HTML <di ...

Exploring ways to loop through a JSON array and embed it into an HTML element

After the ajax request, the data returned is structured as follows: Data = [ ["18/02/2019", "A"], ["19/03/2019", "B"], ["21/05/2019", "C"], ] The ajax request was successful and the data is stored in a variable named Data within a function. ...

Add a slight margin to the bootstrap4 div that has the container-fluid class

I'm in the process of developing a sleek SPA with the help of bootstrap 4.x. Below is the HTML code I've put together: <!DOCTYPE HTML> <html> <head> <!-- Required meta tags --> <meta charset="utf-8"&g ...

Alignment on the top and floated to the right

I am absolutely baffled by this. What is preventing my third div (content-col-text) from floating right? It refuses to move up and align with large-image-container - which is within the outer div wrapper (entry-content).. I have double-checked for any ...

The CSS_MODULES encountered a module build error when utilizing the extract-text-webpack-plugin

While processing CSS with CSS modules in a production environment, I encounter an error, but everything works fine in the development environment. Here is the configuration for webpack.base.js: const path = require("path") const webpack = require("webpac ...

Having trouble enclosing a div within anchor tags in a Rails project

I am facing an issue in my rails app where I have a view containing a div with various content, including links. My goal is to make the entire div clickable. Here is a snippet of code from my view.html.erb file: <a href="/google"> <div class=" ...

Why is the "text-overflow: ellipsis" property of a parent div not functioning properly for its child div?

Why is the CSS property text-overflow: ellipsis not working on a child div with the class name cluster-name? .ft-column { flex-basis: 0; flex-grow: 1; padding: 4px; text-overflow: ellipsis; overflow: hidden; } .ft-column > .cluster-name { ...

Differences in Behavior of Bootstrap Responsive Images Across Safari, Chrome, and Firefox

I am currently facing a challenge in styling an image to fit into the navigation bar of a website and serve as the logo. The issue I'm encountering is that the appearance of the image varies across the three main browsers. Specifically, adjusting the ...

I can't figure out why my CSS transition isn't functioning properly in React 18

I've attempted multiple times to implement a transition on eventBody, but it still isn't functioning correctly. Here's the snippet of code: export function Event({ event }: EventProps) { const [showDropDown, setShowDropDown] = useStat ...

The element's position remains unchanged after the .click re-event in the function

Welcome to my first attempt at using jQuery! Please bear with me as I navigate through this learning process. Here's the challenge: I have a series of elements in my HTML. <div class="garden"> <div class="point left">&#9668;</d ...

Is it possible to eliminate the *:after effect for specific elements in my CSS?

I struggle with CSS, so I decided to use a library that includes the following CSS code: *, *:before, *:after { box-sizing: inherit ; } While this code works well for some views, it messes up others and is unnecessary for some. For instance, in this b ...