I am struggling to close the horizontal space between two flex items in a row

I'm currently working on a web page design and I'm facing an issue with trying to align a clip-art image and its description in a row using flex. Despite using justify-content to adjust the spacing, there seems to be a persistent gap between the two elements. To make this clearer, I've used color coding in the layout.

View the problematic section here

        body {
          background-color: rgb(220, 220, 220);
        }
        nav {
          display: inline;
          text-align: right;
        }
        nav > * {
          margin: 0px 20px 0px 0px;
          font-family: serif;
          text-decoration: none;
          color: black;
        }
        img {
          width: 25%;
          height: auto;
          display: inline;
          text-align: left;
          margin: 0px 600px 0px 0px;
        }
        header {
          display: block;
        
          margin: 0px 0px 0px 0px;
          width: 100%;
        }
        div {
          display: block;
          width: 70%;
          margin: 0px 200px 0px 200px;
          text-align: center;
        }
        #email {
          background-color: white;
          border: black solid;
          width: 300px;
          height: 25px;
          margin: 0px 0px 10px 0px;
        }
        #submit {
          width: 200px;
          height: 25px;
          display: block;
          margin: auto;
          border: solid black;
          background-color: yellow;
        }
        #features {
          display: block;
        }
        #clip {
          width: 100px;
          height: 100px;
        }
        section {
          display: flex;
          flex-direction: row;
          margin: 50px 100px 50px 100px;
          background-color: yellow;
        }
        article {
          display: flex;
          flex-direction: column;
          background-color: pink;
         
        }
        article > * {
          margin: 0px 0px 0px 0px;
        }
      <body>
      <header>
        <img src="https://cdn.freecodecamp.org/testable-projects- fcc/images/product-landing-page-logo.png" alt="original trombones">
        <nav>
          <a href="">Features</a>
          <a href="">How it works</a>
          <a href="">Pricing</a>
        </nav>
      </header>
      <div>
        <h1 style="text-align: center;">Hand-crafted, home-made masterpieces</h1>
        <form id="form">
        <label for="email"></label>
        <input type="email" id="email" placeholder="Enter your email" required>
        <button type="submit" form="form" target="_blank"id="submit"><strong>Let's get started!</strong></button></form>
        </div>
      <div2 id="features">
        <section>
          <img id="clip" src="https://shop.digitemb.com/wp-content/uploads/2019/06/V-20793-Elegant-Prince-Crown-Silhouette-Vector-Art.jpg">
          <article>
            <h3>Premium Materials</h3>
            <p>Our trombones use the shiniest brass which is sourced locally. This will increase the longevity of your purchase.</p>
          </article>
        </section>
        <section>
          <img id="clip" src="https://www.clipartkey.com/mpngs/m/85-853916_fast-delivery-icon-png.png">
          <article>
            <h3>Fast Shipping</h3>
            <p>We make sure you recieve your trombone as soon as we have finished making it. We also provide free returns if you are not satisfied.</p>
          </article>
        </section>
        <section>
          <img id="clip" src="https://us.123rf.com/450wm/iulika1/iulika11810/iulika1181000043/126717986-project-management-icon-vector-illustration.jpg?ver=6">
          <article>
            <h3>Quality Assurance</h3>
            <p>For every purchase you make, we will ensure there are no damages or faults and we will check and test the pitch of your instrument.</p>
          </article>
        </section>
      </div2>
      
    </body>

This code snippet showcases my attempt at getting the items within 'section' in the '#features' element to be closely aligned.

Answer №1

From what I gather, you are looking to showcase your content in a single row without any spaces between them. Here is the solution to meet your requirements. I made changes only in the CSS. Additionally, I updated the structure of the HTML document by adding the head tag and title tag, and included styles within the head tag, which is the proper way to create an HTML page. The complete code looks like this;

<!DOCTYPE html>
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <style type="text/css">
                body {
                    background-color: rgb(220, 220, 220);
                }
    
                nav {
                    display: inline;
                    text-align: right;
                }
    
                /* More CSS styles here */
    
            </style>
            <title>Test</title>
        </head>
        <body>
            <header>
                <img src="https://cdn.freecodecamp.org/testable-projects-fcc/images/product-landing-page-logo.png" alt="original trombones">
                <nav>
                    <a href="">Features</a>
                    <a href="">How it works</a>
                    <a href="">Pricing</a>
                </nav>
            </header>
            
            {/* More HTML content */}

        </body>
    </html>

Note: If you wish to display your content in multiple lines (single item per row), simply make the following adjustments to my modified/updated code;

#features {
    display: block;
}

Remove the background color from section and article, i.e., Yellow and pink. This should address your issue.

Answer №2

give it a shot

div 
{
  display: flex;
  flex-direction: row;
  margin: auto;
  background-color: yellow;
  
}
span
{
  display: flex;
  flex-direction: column;
  background-color: pink;
}

Answer №3

I have revised the code for you, please review the changes:

Snippet

You now have full control over the padding and margins in

.flex-container > img, article

html {background-color: rgb(220, 220, 220)}
#features{width:100%;text-align:center}
#clip{height:200px;width:200px}
.flex-container {
  margin:auto;
  max-width:700px;
  display: flex;
}
.flex-container > img, article {
  background-color: #f1f1f1;
  margin: 10px 5px 0 0;
  padding: 20px;
  font-size: 15px;
}
<div id="features">
        
        <section class="flex-container">
          <img id="clip" src="https://shop.digitemb.com/wp-content/uploads/2019/06/V-20793-Elegant-Prince-Crown-Silhouette-Vector-Art.jpg">
          <article>
            <h3>Premium Materials</h3>
            <p>Our trombones use the shiniest brass which is sourced locally. This will increase the longevity of your purchase.</p>
          </article>
        </section>
        
        <section class="flex-container">
          <img id="clip" src="https://www.clipartkey.com/mpngs/m/85-853916_fast-delivery-icon-png.png">
          <article>
            <h3>Fast Shipping</h3>
            <p>We make sure you receive your trombone as soon as we have finished making it. We also provide free returns if you are not satisfied.</p>
          </article>
        </section>
        
        <section class="flex-container">
          <img id="clip" src="https://us.123rf.com/450wm/iulika1/iulika11810/iulika1181000043/126717986-project-management-icon-vector-illustration.jpg?ver=6">
          <article >
            <h3>Quality Assurance</h3>
            <p>For every purchase you make, we will ensure there are no damages or faults and we will check and test the pitch of your instrument.</p>
          </article>
        </section>
        
</div>

Note: To learn more about flexbox, I recommend visiting this page

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

grid causing images to display incorrectly in incorrect positions

My project consists of 3 component files and a CSS file, but I am facing an issue where the Tiles are slightly off in their positioning towards the top left corner. Although no errors are being thrown, upon using the view grid feature in Firefox, it is ev ...

Implementing the Fixed Header feature in DataTables - A Step-by-Step Guide

I'm encountering an issue with implementing a fixed header for my table using the DataTables plugin. Despite previously asked questions addressing similar problems, I am still unable to resolve it. I suspect that conflicting CSS or missing CDN links c ...

What is the best way to prevent autoplay on a local video embedded in an iframe within a

I have the following code in an HTML5 web page, using div and iframe. Whenever I load the page, video1.mp4 starts automatically. :( I do not want video1.mp4 to start automatically. Can anyone help me with this issue? Thank you very much. ...

Utilizing JSON data retrieved from an API to populate a dropdown menu in HTML

When making a request to an API, I encountered the following error: https://i.sstatic.net/v6PVt.jpg Can anyone advise me on how to insert this into an html select field using jquery ajax? I want it to look something like this: <select> <o ...

My grid layout remains unchanged despite tweaking grid-template-columns

I am currently learning HTML and CSS and experimenting with building a website. My goal is to have 4 boxes aligned next to each other, similar to a navigation bar, but with box items. Here is the code for these boxes: HTML: <section class="boxes&q ...

Trouble getting SVG line to display within Bootstrap 4 flex divs

I am attempting to establish a connection between the first two circular div elements using an SVG line. While inspecting, I can visualize the line but it remains hidden on the page. I tried adjusting the z-index without success. However, increasing the wi ...

The button is unresponsive to the cssStyleDeclaration within the DOM

I've been grappling with a seemingly simple bug for over an hour and could really use a fresh perspective to help me identify the issue. In the code snippet below, I am attempting to change the style of two buttons. One button (deleteBtnToDecorate) r ...

Utilizing Ant Design Icons without an Internet Connection

In my current project, a reactJS application utilizing ant design for the UI was recently deployed to production on locked down computers. These computers lack internet access, causing ant design icons on modals to appear as empty boxes. Upon investigation ...

Automate web tasks with C# WebBrowser

Currently, I am in the initial phases of developing a system to automate the process of data extraction and collection from a website. I have a massive CSV file containing 16,000 lines of data. My goal is to input data from each line into a textarea on a w ...

Positioning of the dropdown in Material UI AutoComplete menus

Is there a way to turn off autocomplete auto position? I would like the autocomplete options to always appear at the bottom. Check out this link for more information! ...

Is there a way for me to determine when my web browser has completed loading the entire page?

Similar Question: How to Detect When a WebBrowser Has Finished Loading a Page Is there a way to determine if my web browser has completed loading all content on the page? In C#, is it possible to display multiple pages in sequence without allowing na ...

Tips for arranging Bootstrap cards in ReactJS so they wrap to a new line after three have been displayed

In my personal portfolio, there is a dedicated page for showcasing various projects using Bootstrap cards. These projects are fetched from a CardData.js file and then mapped to a ProjectCard component. Ideally, I want to display 3 cards per row with consis ...

Creating client side scripts for an ajax call to generate a Json object is simple once you understand the basics

Typically, when I make ajax calls, I request pure HTML. However, for various reasons, I require guidance on constructing a table (let's say of individuals and their information) when receiving a Json object. While I am capable of creating a table in J ...

List style image does not serve its intended purpose

I attempted to personalize my webpage by adding an image to a list, but I couldn't get the list-style image to work. You can view the page at Below is the code I used: CSS /* Fleet List */ ul#flotta li { list-style-image:url("http://ctp.serviziew ...

"Unable to access data from 'POST' form using node.js results in 'undefined'

My task involves sending input data from an HTML page to my localhost server. In the HTML, I am using a "form" like this: <form action="/log-in", method="POST"> <h3 style='font-family: Antic Slab; font-size: 23px;'>Log in to ...

Generate AngularJS ng components programmatically with JavaScript

I am curious about how to generate the following using AngularJS in JavaScript: <input type="text" ng-model="TheText">{{TheText}} For instance, utilizing a method like this: <!DOCTYPE html> <html> <head> </head> ...

Having trouble getting the Bootstrap navbar mega menu to function properly on an Asp.Net Core platform

I attempted to incorporate a Bootstrap navbar mega menu dropdown into my layout using the code from this source: However, after downloading and inserting the code into my layout, the mega menu does not expand or take any action when clicked. In the Chrome ...

Switching between fixed and unfixed divs causes two absolute divs to alternate

I am currently working on a code to keep a fixed div ("two") in place between two absolute positioned divs ("one" and "footer") while scrolling. However, there is an issue that arises when the browser window is resized. The distance between the footer and ...

The dropdown menu does not automatically align with its parent element's position

<div className="inner-dark-section"> <div className="search-section" style={{ width: "100%", position: "sticky", top: "0", ...

Swap out original source files in HTML with minified versions

I have successfully utilized a maven plugin to create a minified and compressed version of my CSS and JavaScript files. Now, I am looking to update the section in my main HTML page that currently loads all those individual files. Here is what it looks lik ...