What is the best way to adjust the spacing between images?

I am currently working on a website project, and I have included the link to the site below:

link

HTML CODE:

 <ul class="instagram-images">
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_1'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_1').'" s="t"]'); ?></a></li>
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_2'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_2').'" wrap_margin="10" s="t"]'); ?></a></li>
                <div class="clearfix"></div>
                <li class="big-news pull-left"><?php echo do_shortcode('[display-posts include_excerpt="false" category="news" image_size="news" wrapper="div" posts_per_page="1" orderby="date"]'); ?></li>
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_3'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_3').'" s="t"]'); ?></a></li>
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_4'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_4').'" s="t"]'); ?></a></li>
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_5'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_5').'" s="t"]'); ?></a></li>

                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_6'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_6').'" s="t"]'); ?></a></li>
                <li class="big-news pull-right rightm"><?php echo do_shortcode('[display-posts include_excerpt="false" offset="1" category="news" image_size="news" wrapper="div" posts_per_page="1" orderby="date"]'); ?></li>
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_7'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_7').'" s="t"]'); ?></a></li>
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_8'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_8').'" s="t"]'); ?></a></li>

                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_9'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_9').'" s="t"]'); ?></a></li>
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_10'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_10').'" s="t"]'); ?></a></li>

                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_11'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_11').'" s="t"]'); ?></a></li>
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_12'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_12').'" s="t"]'); ?></a></li>
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_13'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_13').'" s="t"]'); ?></a></li>
                <li><a target="_blank" href="<?php echo ot_get_option('instagram_photo_14'); ?>"><?php echo do_shortcode('[instagram_embedding url="'.ot_get_option('instagram_photo_14').'" s="t"]'); ?></a></li>
            </ul>

CSS CODE:

.instagram-images li{
  width:18%;
  margin:0 0.8%;
  display:inline-block;
}
.instagram-images li img{
  margin:0.5% 0;
}

To provide a clearer understanding of what is being described, I have attached an image that illustrates the specific design requirements.

https://i.sstatic.net/m7e01.jpg

The main goal is to achieve a symmetrical and evenly spaced layout throughout the design elements. If there are any uncertainties or further clarifications needed, please feel free to reach out.

Thank you in advance!

Answer №1

The reason for this issue is due to the li elements being displayed as inline elements, causing browsers to add spaces between them as if they were regular text. To fix this, you can set the font-size of the ul.instagram-images > li to 0:

ul.instagram-images > li {
  font-size: 0;
}

ul.instagram-images > li a{
  font-size: 14px; // reset font size
}

However, this solution may not work well on all mobile browsers as some have minimum font size restrictions. Instead of using the li element, consider adding float: left; to eliminate gaps. The success of this method depends on your layout requirements.

Another approach is to remove whitespaces between </li><li> tags to prevent spacing issues. Additional tricks can be found here: css-tricks.com

Answer №2

When working with inline blocks, it's important to note that there will be spaces between them if the markup contains spaces.

To address this issue, you can either remove the spaces or explore alternative methods such as using float or flexbox.

Consider a Raw Approach

ul {
  text-align: center;
}

li {
  list-style: none;
  display: inline-block;
  border: 1px solid #000;
}
<ul>
  <li>1</li><li>2</li><li>3</li>
</ul>

Alternatively

ul {
  text-align: center;
}

li {
  list-style: none;
  display: inline-block;
  border: 1px solid #000;
}
<ul>
  <li>
    1
  </li><li>
    2
  </li><li>
    3
  </li>
</ul>

Utilize Comments

ul {
  text-align: center;
}

li {
  list-style: none;
  display: inline-block;
  border: 1px solid #000;
}
<ul>
   <li>1</li><!--
--><li>2</li><!--
--><li>3</li>
</ul>

Avoid Explicitly Closing li Tags

ul {
  text-align: center;
}

li {
  list-style: none;
  display: inline-block;
  border: 1px solid #000;
}
<ul>
  <li>1
  <li>2
  <li>3
</ul>

PS: Referenced from this answer (in Russian).

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

The art of jQuery: Effortlessly animate the deletion of a CSS property

When using jQuery, I often "collapse" certain DOM elements by decreasing their width to 0px and fading them out. Here is an example: $(".slideoutmenu").animate({ width: 0, opacity: 0}, function() { $(this).hide(); }); The widths of these elements can var ...

Using the jQuery Selector with multiple IDs will yield different results compared to using a single ID selector

Initially, I set up some dropdown menus to determine which one has been selected and then load the elements with no issues. However, when I added a new set of dropdowns, my existing function started applying to this one as well because it was too broad. ...

Why isn't the image showing up as a list style?

I can't seem to get the image to show up on my page. Can anyone help me figure out what's wrong? ul li { background-image: url(logo.png); background-repeat: no-repeat; padding-left: 0px; } This is what I'm currently seeing: This is what ...

The event listener for changing radio buttons

Imagine we have two radio buttons <input type="radio" value="val1" name="radio1" onChange="change()"/> <input type="radio" value="val2" name="radio1" onChange="change()&quo ...

Submitting an HTML form to trigger a PHP function through AJAX

I am currently working on a task that involves POSTing an email address entered in an HTML form to a PHP script for storage in a database. The script should also handle error messages if the user inputs an invalid email address. I want to make this process ...

Styling is lost in FancyBox popup when loading Partial View

I've been attempting to incorporate a partial view into my MVC project using fancybox. It seems to be loading the content correctly, mostly anyway, as it tends to cut off part of the page and loses all styling from the view upon loading. Even after i ...

Social Engine is incapable of analyzing the HTML code

Currently working on a website using Social Engine 4.8.9 version that is still in development mode. Upon inspecting the html code with the chrome inspector, I find it incredibly complex to decipher. For instance, when I click on the login page link http:// ...

Solving the default font problem in Laravel

I've been working on a project using Laravel and Bootstrap 4. Recently, I decided to switch from the default Laravel font, Nunito, to Lato. So, I made the necessary changes in my app.css file: @import url(https://fonts.googleapis.com/css?family=Nun ...

Connecting files within a directory using the Shiny framework

I am working on a shiny app that will display the files within a folder and give users the option to open or download them. For example, let's say I have 3 files in a folder: file1.txt file2.bmp file3.jpg I want my app to list these files and allo ...

What is the best way to showcase a half star rating in my custom angular star rating example?

component.ts import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { projectRating ...

Steps to transfer text from one input field to another by clicking a button using JavaScript

Hello, I am new to Javascript so please forgive me if my question seems silly. I have been tasked with creating a form containing two input fields and a button. When the button is clicked, the text entered in the first field should move to the second field ...

Angular's Innovative 3D-esque Carousel Rotation

My goal is to design a pseudo-3d carousel with 5 items, like the example below (and have them rotate around): https://i.sstatic.net/FtcSe.png I came across this fantastic stackblitz as a base, and I've been tinkering with it for hours attempting to ...

How can you utilize positioning and margins with Flexboxes?

<template> <div class="flex justify-center"> <div class="h-px-500 md:w-1/6 bg-orange-200 text-center">1</div> <div class="h-px-500 md:w-1/6 bg-orange-300 text-center">2</div> <div class="h-px-500 md:w-1/ ...

Get the username from Parse instead of using the ObjectID

When using angular and Parse for JavaScript, I have implemented a search field where an admin can input the objectid of a user to display their details. However, I would like to modify this functionality so that the admin can enter the username instead of ...

Using Bootstrap 4 causes text to wrap buttons onto a separate line

I am facing an issue with my HTML page that displays correctly on medium and large devices but encounters difficulties on smaller screens. When the screen size decreases, the text inside the grey elements takes up all the space, causing the two right-float ...

How can I implement a loop to showcase bootstrap popover content?

I'm having issues with my popover content always displaying the first item in the list. How can I make it display each individual item? Below is the snippet of Razor HTML code I am using: @{ foreach(item in Model.SomeObject) { <div clas ...

What is the best way to create a functional submenu using Bootstrap?

I'm trying to create a functional Bootstrap submenu that is collapsible and includes multiple options to choose from. However, I'm struggling to figure out how to implement it and haven't been able to find a solution anywhere. <!DOCTYP ...

When the Bootstrap carousel slides, enhance the navbar text with motion blur effects

One issue I'm facing is that when the bootstrap carousel changes the image, it adds the class "next" (transform: translate3d(100%, 0, 0); ) to the item and causes motion blur in my navbar menu text. https://i.sstatic.net/kRnb4.png You can check out a ...

The sizing of cards in Bootstrap is not uniform

I'm currently working on a page layout using Bootstrap. I've included 3 cards in a row, but they are not displaying at equal sizes for some reason. The content within the cards, including headings and images, seems to be affecting their overall s ...

What is the best way to restrict the row height to match a set column height in Bootstrap?

I need a row with 2 columns, where the height of the row is determined by the content of column 1. Column 2's content should be truncated if needed. <div class="container"> <div class="row"> <div class="col- ...