如何在行內塊元素之間移除空格?


我們可以輕鬆刪除行內塊元素之間的空格。在繼續之前,我們首先建立一個 HTML 文件,並在其中新增帶有空格的行內塊元素 −

示例

<!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>

現在,讓我們看一些示例,以刪除行內塊元素之間的空格 −

刪除行內塊元素之間的空格

我們可以透過將無序列表項安排在一行中來刪除行內塊元素之間的空格 −

示例

<!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>

透過跳過關閉標籤刪除行內塊元素之間的空格

我們還可以透過跳過關閉標籤來刪除空格 −

示例

<!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>

更新於: 17-Oct-2022

646 瀏覽量

開啟你的 職業生涯

完成課程即可獲得認證

開始
廣告