Home > Web Front-end > CSS Tutorial > How Can I Eliminate Unwanted Spaces Between Inline-Block List Items?

How Can I Eliminate Unwanted Spaces Between Inline-Block List Items?

Linda Hamilton
Release: 2024-12-17 21:26:15
Original
575 people have browsed it

How Can I Eliminate Unwanted Spaces Between Inline-Block List Items?

Whitespace in Inline-Block List Items Solved

Inline-block list items often exhibit unwanted spaces between them. This issue arises due to the whitespace-dependent nature of inline-block elements and the font's spacing settings.

To resolve this, consider the following measures:

  • Block Together: Merge your list items into a single line for optimal spacing.
  • Join Tags: Wrap the list item tags together, eliminating the space between each item:
<ul>
    <li><div>first</div></li><li><div>first</div></li><li><div>first</div></li><li><div>first</div></li>
</ul>
Copy after login

Alternatively, you can eliminate the whitespace by setting the font size of the parent element to 0:

ul {
    font-size: 0;
}

ul li {
    font-size: 14px;
    display: inline-block;
}
Copy after login

This method resets the font spacing for the parent element and adjusts it separately for the individual list item content.

The above is the detailed content of How Can I Eliminate Unwanted Spaces Between Inline-Block List Items?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template