How to press the blocks to each other?
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> How to press the blocks to each other?
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> The fact is that inline-blocks are like words.
If there are white space characters in the markup, the browser will display a space.
I will list a few normal ways to remove gaps.
There is an armful of not too normal - I will not say anything about them.
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> 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> 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> ul { text-align: center; } li { list-style: none; display: inline-block; border:1px solid #000; } <ul> <li>1 <li>2 <li>3 </ul> In css, there is no honest way to not show spaces between elements at all. There is a crutch with a font-size om (described in the next answer ), which not only ruins the inheritance of the font size, but also does not work in some browsers; There is a crutch with word-spasing / letter-spacing / margin , in which it is not only that each browser has its own design, but it is also attached to the font, since the width of the space is different in different fonts. Removing the space from the markup is an honest way, the others are not. And if you only need css, then you should abandon the inline-block and use flex or float , but this is not the question.
But what happens to those who think otherwise.
There is no markup binding here, however, the flex-box is in some way similar to tables and is not recommended for significant parts of the site (for example, layout) due to possible performance degradation. In addition, it is worth checking browser support and the need to use prefixes.
ul { display: flex; justify-content: center; } li { list-style: none; border: 1px solid #000; } <ul> <li>1</li> <li>2</li> <li>3</li> </ul> font-size much more normal than relying on the fact that the programmer will retain such markup when dragging on the engine, for example - xajafont-size om, which not only ruins inheritance, but does not work in some browsers; There is a crutch with word-spasing / letter-spacing , in which it is not only that each browser has its own design, but it is also attached to the font, since the width of the space is different in different fonts. Removing the space from the markup is an honest way, the others are not. And if you only need css, then you should abandon the inline-block and use flex or float , but this is not the question. - Qwertiy ♦There are a lot of solutions, http://codepen.io/anon/pen/megQVe is described in some detail here, the simplest is to change the font-size ul and li separately
ul { text-align: center; font-size: 0px; } li { list-style: none; display: inline-block; border:1px solid #000; font-size: 16px; } <ul> <li>1</li> <li>2</li> <li>3</li> </ul> ul { text-align: center; } li { list-style: none; display: table-cell; border:1px solid #000; } <ul> <li>1</li> <li>2</li> <li>3</li> </ul> Source: https://ru.stackoverflow.com/questions/474742/
All Articles