Home > Article > Web Front-end > How to remove spaces between inline-block elements?
We can easily remove spaces between inline block elements. Before continuing, let's first create an HTML document and add an inline block element with spaces -
<!DOCTYPE html> <html> <head> <title>Inline block elements</title> <style> li { display: inline-block; width: 150px; font-size: 18px; } li:nth-child(1) { background: green; color: white; } li:nth-child(2) { background: orange; color: black; } li:nth-child(3) { background: blue; color: white; } li:nth-child(4) { background: red; color: black; } </style> </head> <body> <h1>Free Tutorials</h1> <p>We have the following tutorials right now:</p> <ul> <li>Java</li> <li>Python</li> <li>Machine Learning</li> <li>Automation</li> </ul> </body> </html>
Now let’s look at some examples of removing spaces between inline block elements -
We can remove spaces between inline block elements by arranging unordered list items in one line -
<!DOCTYPE html> <html> <head> <title>Inline block elements</title> <style> li { display: inline-block; width: 150px; font-size: 18px; } li:nth-child(1) { background: green; color: white; } li:nth-child(2) { background: orange; color: black; } li:nth-child(3) { background: blue; color: white; } li:nth-child(4) { background: red; color: black; } </style> </head> <body> <h1>Free Tutorials</h1> <p>We have the following tutorials right now:</p> <ul> <li>Java</li><li>Python</li><li>Machine Learning</li><li>Automation</li> </ul> </body> </html>
We can also remove spaces by skipping category tags -
<!DOCTYPE html> <html> <head> <title>Inline block elements</title> <style> li { display: inline-block; width: 150px; font-size: 18px; } li:nth-child(1) { background: green; color: white; } li:nth-child(2) { background: orange; color: black; } li:nth-child(3) { background: blue; color: white; } li:nth-child(4) { background: red; color: black; } </style> </head> <body> <h1>Free Tutorials</h1> <p>We have the following tutorials right now:</p> <ul> <li>Java <li>Python <li>Machine Learning <li>Automation </ul> </body> </html>
The above is the detailed content of How to remove spaces between inline-block elements?. For more information, please follow other related articles on the PHP Chinese website!