Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove Vertical margins between Flex Children

I’m trying to create a simple grid-based ASCII graphics system in HTML.
The system interprets an array of single-character strings as a grid, with regular partitions representing rows.
These rows are then appended to some parent via a DIV or P container.

Aside from negative margins, how can I stylize this so that the distance between rows and columns are the same?

Here’s what I’ve tried so far:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.grid {
  display: flex;
  flex-direction: column;
  row-gap: 0px;
  font-family: monospace;
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
  <div class="grid">
    <div>XXXX</div>
    <div>XXXX</div>
    <div>XXXX</div>
    <div>XXXX</div>
  </div>
</body>

</html>

To be clear, I need the characters to sit flush against each other.

>Solution :

One way would be to set line-height to the width of the character (8px):

.grid {
  display: flex;
  flex-direction: column;
  font-family: monospace;
  line-height: 8px;
}
<div class="grid">
  <div>XXXX</div>
  <div>XXXX</div>
  <div>XXXX</div>
  <div>XXXX</div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading