The inline-block property value becomes very useful when you need to control margin and padding on "inline" elements, so you no longer need to make these elements "block" or "float". But there is a problem, when using inline-block, the whitespace between HTML elements will show up on the page. Very annoying. There are a few ways to remove these whitespaces; one of them is quite clever. Method 1: No space between elements A 100% surefire way to fix this is to not leave any whitespace between elements in your HTML: CSS CodeCopy content to clipboard
Of course, this looks messy and makes the code difficult to maintain, but it is practical, intuitive, and most importantly... reliable. Method 2: Set font-size: 0 on the parent element The best solution to this whitespace issue is to set font-size: 0 on the parent element of these inline-block elements. If you have an inline-block <LI> inside your <UL>, you can do this: XML/HTML CodeCopy content to clipboard
In order to prevent the font size of the parent element from affecting the child element, you need to re-set the font-size value on the child element, which is usually simple. The only time you might run into trouble is if you use relative font sizes. But most of the time, this method can solve your problem. Method 3: HTML Comments This method is a bit more brute force, but it works just as well. Padding HTML elements with comments has the same effect as having no space between them: XML/HTML CodeCopy content to clipboard
In one word…disgusting. In two words…disgusting. In three words….OK, you get it. But it works! Method 4: Negative Margins Very similar to method 2 , sorry. You can take advantage of the flexibility of inline-block and give them a negative margin to hide the whitespace: XML/HTML CodeCopy content to clipboard
This method is the least recommended because you have to take various situations into account and sometimes there will be some unforeseen gaps. It’s best not to use this trick. Method 5: Chain Link Another way to take advantage of HTML markup is to place the closing tag of an element close to the opening tag of the next element: XML/HTML CodeCopy content to clipboard
Not as ugly as HTML comments, but I'd rather remove those whitespaces by hand regardless of code readability. No approach is ideal, but leaving no whitespace on a web page is a bad approach. This is not to warn you not to use inline-block. Inline-block is still very useful. You just need to understand how to deal with the whitespace inside it. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: MySQL beginners can say goodbye to the troubles of grouping and aggregation queries
>>: Using vue3+threejs to imitate the iView official website big wave special effects example
Rancher deployment can have three architectures: ...
CSS matches multiple classes The following HTML t...
Table of contents 1. Download 2. Deployment 1.Ngi...
Table of contents Preface Rendering Example Code ...
This article example shares the specific code of ...
Preface Previously, static IPs assigned using pip...
1. Navigation: Unordered List vs. Other Label Ele...
Rendering After looking up relevant information o...
Foregoing: This document is based on the assumpti...
The code under the easyui framework is as follows...
Table of contents What is pre-analysis? The diffe...
Table of contents Purpose Module Installation Bas...
Table of contents Reactive Function usage: toRef ...
This article example shares the specific code of ...
Networks usage tutorial Official website docker-c...