Ways to manage the gap among flex items

I'm currently going through some educational material on Codeacademy, and I'm curious about how I can control the spacing between the "locations" text and the three divs below it. The task requires me to create a 15px gap between them, but I am unsure of how to achieve that. Right now, there is just a default spacing that I cannot figure out how it is being calculated.

html {
  text-align: center;
}

.location-container {
  background-image: url(https://content.codecademy.com/courses/freelance-1/unit-4/img-locations-background.jpg);
  height: 700px;
  width: 1200px;
  display: flex;
  justify-content: center;
  align-content: center;
  flex-wrap: wrap;
}

#local {
  background-color: blueviolet;
}

.location-columns {
  display: flex;
  justify-content: center;
  width: 100%;
  gap: 30px;
  color: white;
}

.locations {
  background-color: black;
  width: 300px;
}
<div class="location-container">

  <h2 id="local">Locations</h2>

  <div class="location-columns">
    <div class="locations">
      <h3>Downtown</h3>
      <h5>384 West 4th St</h5>
      <h5> Suite 108</h5>
      <h5>Portland, Maine</h5>
    </div>
    <div class="locations">
      <h3>East Bayside</h3>
      <h5>3433 Phisermans Avenue</h5>
      <h5>(Northwest Corner)</h5>
      <h5>Portland, Maine</h5>
    </div>
    <div class="locations">
      <h3>Oakdale</h3>
      <h5>515 Crescent Avenue</h5>
      <h5> Second Floor</h5>
      <h5>Portland, Maine</h5>
    </div>
  </div>

If you have any insights or suggestions, they would be greatly appreciated.

Answer №1

When it comes to heading elements, they typically have large upper and lower margins as part of the default browser styles.

To adjust this for elements within .locations, you can transform it into a flex container and utilize row-gap to manage the vertical spacing:

html {
  text-align: center;
}

.location-container {
  background-image: url(https://content.codecademy.com/courses/freelance-1/unit-4/img-locations-background.jpg);
  height: 700px;
  width: 1200px;
  display: flex;
  justify-content: center;
  align-content: center;
  flex-wrap: wrap;
}

#local {
  background-color: blueviolet;
}

.location-columns {
  display: flex;
  justify-content: center;
  width: 100%;
  gap: 30px;
  color: white;
}

.locations {
  background-color: black;
  display: flex;
  flex-direction: column;
  row-gap: 30px;
  padding: 30px;
  width: 300px;
}

.locations>* { margin: 0; }
<div class="location-container">

  <h2 id="local">Locations</h2>

  <div class="location-columns">
    <div class="locations">
      <h3>Downtown</h3>
      <h5>384 West 4th St</h5>
      <h5> Suite 108</h5>
      <h5>Portland, Maine</h5>
    </div>
    <div class="locations">
      <h3>East Baysuide</h3>
      <h5>3433 Phisermans Avenue</h5>
      <h5>(Northwest Corner)</h5>
      <h5>Portland, Maine</h5>
    </div>
    <div class="locations">
      <h3>Oakdale</h3>
      <h5>515 Crescent Avenue</h5>
      <h5> Second Floor</h5>
      <h5>Portland, Maine</h5>
    </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 is the best way to make a line widget that has rounded edges at both the beginning and end?

I've been scouring the internet for a solution to this problem, but so far I haven't had any luck. My goal is to design a horizontal line with dots at each end, similar to this example. Does anyone know how I can achieve this using CSS? I atte ...

Conceal an entire div using CSS, especially if a portion of it remains unoccupied

Is there a way to conceal an entire division if a part of it is void? For instance, if "dd" is empty as indicated below, can I hide the entire class "test" so that the keyword Restrictions does not display either? I attempted .test dd:empty { display: none ...

Adjust the Bootstrap row height to both occupy the full height while also being limited by the height of a designated container

Here's a puzzling question.. I've got a container with multiple rows, and I want these rows to completely fill the container's height without overflowing. I'm trying to avoid manually setting the row heights. When I add class="h-1 ...

Enhancing user experience with Bootstrap's body padding and customizable scrollbars

Recently, I encountered an issue with the footer color in bootstrap. To fix this problem, I created a div and removed the extra padding from the body element. You can view the code snippet here: jsfiddle.net/wctGM/9/ However, when viewing the mobile ver ...

Positioning Data Labels Outside of Pie or Doughnut Charts in Chart.js

I am currently working on a large-scale project and I am in need of a way to position the labels outside of pie charts or doughnut charts. I came across a plugin called outerLabels on GitHub which seems to be the perfect solution for what I need, but I am ...

How do I go about configuring the uploaded image?

Here is a sample of my HTML code: <div class="images"> <figure> <button id="upload-add-product" class="icon-plus"></button> <input id="upload-file" type="file" style="display: none;" multiple/> </fi ...

The previous button on Owl Carousel seems to be malfunctioning after navigating from a different page

In my case, I have two distinct pages: let's call them the first and second pages. On the first page, I utilize an owl carousel slider with a tag that links to a specific slide on the second page's owl carousel slider using an ID. Meanwhile, on ...

The Art of HTML and CSS Layouts

My code is displaying a layout where the 'Login or Signup' link is not aligning to the right side of the page as intended. Can anyone help me with this issue? HTML <header> <h1>Heading</h1> <p>A clean, minimal, gri ...

sticky position is functional in Chrome, however it does not work in Firefox

I am looking to create a vertical div that stretches to the height of its parent container and contains smaller divs. If there is extra space, all divs except for the last one should be positioned at the top, with the last div placed at the bottom. I used ...

Modifying alignment of buttons in React components

Transforming the typical Tic Tac Toe game from the React tutorial, with an added one-player feature. Oddly, button alignment shifts out of place once a value is inserted; causing the button to drop by about 50px until the row is filled with values, after ...

Help with guiding and redirecting links

Here's the code snippet: <script> if(document.location.href.indexOf('https://thedomain.com/collections/all?sort_by=best-selling') > -1) { document.location.href = 'https://thedomain.com/pages/bestsellers'; } </script& ...

Tailored design - Personalize interlocking elements

I am currently working on a custom theme and I am trying to adjust the font size of Menu items. In order to achieve this, I have identified the following elements in the tree: ul (MuiMenu-list) MuiListItem-root MuiListItemText-root If I want to modify th ...

The functionality of using variables in conjunction with the .insertAfter method appears to be

As a novice coder with limited English skills, I apologize in advance. Here is the CSS code snippet I am working with: #wrapper{ width: 200px; height: 300px; border: solid 1px #000; overflow: visible; white-space: nowrap; } .page{ ...

When clicking, populate the content of another div in a vertical top-to-bottom fashion

I am in the process of creating a functionality where clicking on one element will fill another element's content from bottom to top. Although I have managed to make it work on hover, the same functionality is not triggered when clicking on the eleme ...

Tips for increasing the number of pixels in the current position of an element?

I need to shift an image to the right by adding pixels to its current left position. The challenge arises when the image, positioned absolutely, goes back to its nearest relative parent (the container) and creates a strange visual effect. Within my flex c ...

Ways to remove content that exceeds the boundaries of a div element

I am facing a challenge with a parent div that has a specified size. Inside this parent div, there are other child divs, and if any of those child divs start displaying their content outside of the parent div, I want to completely remove that div. I do not ...

What is the best way to assign an ID to the initial table header in an asp:DataGrid for CSS styling purposes?

I am looking for a way to customize the first element in the table headers row using CSS without relying on :first_child selector. Example Code: <asp:TemplateColumn HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left"> <Heade ...

Tips for aligning the dropdown menu to start from the border of the menu bar instead of displaying directly below the text

I have designed a menu-header section for my website, inspired by this image. I created a fiddle to showcase it. However, I am facing an issue where the dropdown elements for "PROGRAMS" and "WORLD OF NORTHMAN" should start from the border of the header ins ...

Different ways to display an HTML page in a well by utilizing a div tag and jQuery from a side menu

Check out my Tutorial Page! Currently, I am working on a simple tutorial page utilizing bootstrap 3. My goal is to showcase the HTML file content within the well container on the right side of the page. However, I am facing challenges as I do not want to ...

Navigating to different sections of a single page using Bootstrap

I'm feeling a bit lost when it comes to understanding how linking to an element within a page functions. As I delve into the starter template for Twitter Bootstrap, I encounter the following code snippet in the navbar: <ul class="nav navbar-nav"&g ...