What has caused the space between these articles?

I have created a section containing three articles and I am confused about the margin/padding between the articles:

This is my HTML code:

<section id="home">

 <article>
<h1>Overview</h1>
 </article>
 <article>
<h1>People</h1>
 </article>
 <article>
<h1>Links</h1>
 </article>

 </section> 

And this is my CSS code:

section {
    width: 87%;
    margin: 0px auto;
 }

article {
    width:33%;
    font-family: 'Open Sans', sans-serif;
    background-color:blue; 
    display: inline-block;
    margin:0px;
    padding: 0px;
 }

Answer №1

Consider replacing the inline-block with block and incorporate float:left. Check out this demo on JSFiddle

JSFIDDLE DEMO

Answer №2

There is some unnecessary whitespace in between the display:inline-block elements. A simple solution is to remove them, like this:

<section id="home">
    <article><h1>Overview</h1></article><!--
    --><article><h1>People</h1></article><!--
    --><article><h1>Links</h1></article>
</section>

Alternatively:

<section id="home">
    <article><h1>Overview</h1></article><article><h1>People</h1></article><article><h1>Links</h1></article>
</section>

JSFiddle link

Another option is to add font-size:0; to the parent container, as shown in this example.

Answer №3

Your browser automatically includes spaces.

An effective solution for this issue is to apply font-size:0 to the parent container and then assign a suitable font size to the child elements.

To address your specific situation, follow these steps:

section {
    font-size: 0;     //Should be set to zero
}

article {
    font-size: 10px;  //Can be adjusted as needed

    width:33%;
    font-family: 'Open Sans', sans-serif;
    background-color:blue; 
    display: inline-block;
    margin:0px;
    padding: 0px;
}

Answer №4

When you have any two inline or inline-block elements in your markup, they will be displayed with a white space between them, regardless of how many spaces or new lines separate them.

For instance, if you have these 3 divs, the output will still be hello world:

<div>hello world</div>

<div>hello
world</div>

<div>

   hello


       world
</div>

This behavior occurs because the text nodes inside are treated as inline.

If you want to avoid this spacing issue, ensure that the opening <article> tag immediately follows the closing </article> tag:

<section id="home">
 <article>
<h1>Overview</h1>
 </article><article>
<h1>People</h1>
 </article><article>
<h1>Links</h1>
 </article>

 </section>

Check out this jsFiddle for reference.

In situations where you don't want the default whitespace, such as wanting 'helloworld' instead of 'hello world', simply remove the extra spaces in your HTML markup between the words.

Answer №5

When it comes to display inline block, it's essentially an inline element with block properties. This means that if there is any white space or line breaks between elements, it will create gaps.

To avoid these gaps and ensure compatibility with older browsers, I recommend using display: block and float: left instead. If you still prefer to use inline-block, make sure to remove any white space so that the tags of the elements are directly adjacent to each other.

For more information on display:inline-block, check out this article:

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

Modify the appearance of the PrimeReact navigation bar

I am struggling to change the background color of the navbar in my PrimeReact application. I have tried adding CSS styling in various places, but nothing seems to work. All I want is to customize the background color while keeping the default PrimeReact ...

Is it possible for me to use AJAX to load content from a string? I am attempting to postpone the activation of certain HTML

I need help optimizing my HTML page that includes certain sections with large Javascript files and images, which are initially hidden. Even when set to "display: none," the browser still loads all the content. One solution could be moving those sections in ...

Tips for getting the DIV:hover effect to work in Internet Explorer 8

Can someone provide me with the steps to get DIV:Hover functioning in Internet Explorer 8? ...

an occurrence of an element being rendered invisible, within an instance of an element being rendered as flexible,

I am trying to create a button that will show a list of elements. Within this list, there is another button that can be used to either close the list or hide it entirely. However, for some reason, my code is not functioning properly. let btn1 = documen ...

Issue with Trix text editor not triggering the change event

Lately, I've been facing some difficulties in getting the tirx-change event to trigger when there are changes in the content of a trix-editor. Despite using React JS for the view, I haven't been able to identify the problem. Below is the code sni ...

Adaptive search bar and components housed within a casing

I am struggling to create a responsive box with a search feature for a mobile website. My plan is to incorporate jquery functions into the site, so I need to design an outer container that will house a distinct logo and search bar. However, when I test thi ...

Troubleshooting a unique CSS problem on an Android PhoneGap

We are currently working on an Android application using PhoneGap, HTML, CSS, and jQuery Mobile. After compiling the application in Eclipse, everything seems to work correctly. However, I am facing an issue where my CSS styles are not updating when recompi ...

Eliminating the 'white-space' surrounding concealed images

I am currently working on a project where I have a list of images that need to be hidden or shown based on the click event of specific <li> elements. While I have managed to achieve this functionality successfully, I am facing an issue with white spa ...

"Unfortunately, the JavaScript external function failed to function properly, but miraculously the inline function

Struggling to create a fullscreen image modal on the web? I was able to get it working fine when embedding the script directly into my HTML file, but as soon as I moved it to an external JS file, things fell apart. I've double-checked all the variable ...

What's the best way to modify HTML element classes using Javascript?

I have designed a custom cms theme with various customization options that I wish to showcase in a live demo. My goal is to implement Javascript style switchers or modifiers where users can choose values from checkboxes or select tags, and see their select ...

Transforming table headers in Rmarkdown ioslides

I am experimenting with creating a custom table format for tables generated using the ioslides_presentation output type in Rmarkdown with Rstudio Version 0.98.1028. However, I'm facing difficulty in modifying the styling of the table headers. Below i ...

Strategies for optimizing PPI and DPI in responsive design

Imagine having two monitors: one 15.5 inches with a resolution of 1920 x 1080 and the other 24 inches with the same resolution. The first monitor has a pixel density of around 72 PPI, while the second has around 90 PPI. If I apply a media query in CSS for ...

Issue with maintaining fixed space above navbar in HTML/CSS code

I'm struggling to make my navbar sticky on my website without any space above it. Can someone help me with this issue? Here is the URL to my site: My CSS looks like this: body { font-size: 12px; line-height: 22px; font-family: Arial, H ...

Start fresh with the count for every individual table

In my HTML document, I have multiple tables with columns that have classes "valuation" and "valuation_all". If one cell in the "valuation" column contains the text "FAIL", then the corresponding cell in the "valuation_all" column should display "FAIL"; oth ...

HTML5 Video Frozen in Place on Screen's Edge

I am encountering a problem specifically on Webkit, particularly in web view on iOS. When I tested it on desktop Chrome, the issue did not appear. Here is the Portrait image and Here is the Landscape image The video seems to be fixed in one position rega ...

What causes an iframe to scroll horizontally when scaled?

I'm in the process of resizing an iframe element on my webpage using a CSS media query to adjust its dimensions. However, when I scale it down and interact with the iframe, my webpage starts scrolling horizontally. The issue is evident when using Chro ...

What is the process for including echo HTML field in the WooCommerce order view?

I have successfully added HTML input fields within functions.php. However, these echoed fields are not displaying in WooCommerce orders after placing an order. I am looking for a way to include the values and labels of these fields in the orders view wit ...

Fetching dynamic information via AJAX for a jQuery tooltip

I have successfully loaded content via AJAX, including a UL element with li items that each have tooltips. Now I want to load tooltip content via AJAX for each individual li item. How can I achieve this? Currently, I am making an AJAX call to load the li ...

What is the method to extract div text using Python and Selenium?

Is there a way to extract the text "950" from a div that does not have an ID or Class using Python Selenium? <div class="player-hover-box" style="display: none;"> <div class="ps-price-hover"> <div> ...

I am searching for a way to apply a conditional class to the chosen element in react, as the toggle method does not

I'm working on customizing a dropdown menu and I want to add a functionality where if a parent li menu has an arrow class before the ul element, then clicking on that parent li menu will add a class called showMenu only to that specific sub-menu. Her ...