I started writing a site

*{ margin: 0; padding: 0; } #alive{ display: inline-block; width: 25%; height: 1000px; background-color: rgb(255, 128, 0); } #mid{ display: inline-block; width: 49%; height: 1000px; background-color: red; } #rhyme{ display: inline-block; width: 25%; height: 1000px; background-color: rgb(255, 128, 0); } 
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="ccc.css" type="text/css"/> </head> <body> <div> <div id="alive"></div> <div id="mid"></div> <div id="rhyme"></div> </div> </body> </html> 

But between the blocks there is a small empty space, I can not understand where it comes from? enter image description here

  • one
    These are line breaks between divs that are written in your code - andreymal
  • Isn't the transfer by the br tag done? - Victor Morozov
  • This is not the transfer. You have in the code hyphens that you made Enter'om - so they are displayed - andreymal

4 answers 4

For some reason, you set inline behavior for blocks, and they have "letter-letter" intervals (like any string elements).

There are different solutions to this problem. For example, simply comment out these indents:

 *{ margin: 0; padding: 0; } #alive{ display: inline-block; width: 25%; height: 1000px; background-color: rgb(255, 128, 0); } #mid{ display: inline-block; width: 49%; height: 1000px; background-color: red; } #rhyme{ display: inline-block; width: 25%; height: 1000px; background-color: rgb(255, 128, 0); } 
 <div id="alive"></div><!-- --><div id="mid"></div><!-- --><div id="rhyme"></div> 

But it is better to use flex or float if you need to line up the blocks. Setting them inline-block is not a good solution.

    Another cool way to get rid of spaces is to make them zero size using font-size: 0px on the container. However, in the future it is necessary not to forget to return to the descendants the default font size.

     * { margin: 0; padding: 0; } .line { font-size: 0; } .line > * { font-size: initial; } #alive { display: inline-block; width: 25%; height: 1000px; background-color: rgb(255, 128, 0); } #mid { display: inline-block; width: 49%; height: 1000px; background-color: red; } #rhyme { display: inline-block; width: 25%; height: 1000px; background-color: rgb(255, 128, 0); } 
     <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="ccc.css" type="text/css"/> </head> <body> <div class="line"> <div id="alive"></div> <div id="mid"></div> <div id="rhyme"></div> </div> </body> </html> 

      It is best to use the flex-box as Qlasandr said .

      Flexbox guide - link

      This issue is solved in a couple of lines:

       .parent{ width: 100%; display: flex; flex-direction: row; height: 1000px; } #alive{ width: 25%; background-color: rgb(255, 128, 0); } #mid{ width: 50%; background-color: red; } #rhyme{ width: 25%; background-color: rgb(255, 128, 0); } 
       <div class="parent"> <div id="alive"></div> <div id="mid"></div> <div id="rhyme"></div> </div> 

        The usual hack everyone knows - you put comments between the blocks

         *{ margin: 0; padding: 0; } #alive{ display: inline-block; width: 25%; height: 1000px; background-color: rgb(255, 128, 0); } #mid{ display: inline-block; width: 49%; height: 1000px; background-color: red; } #rhyme{ display: inline-block; width: 25%; height: 1000px; background-color: rgb(255, 128, 0); } 
         <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="ccc.css" type="text/css"/> </head> <body> <div> <div id="alive"></div><!-- --><div id="mid"></div><!-- --><div id="rhyme"></div> </div> </body> </html> 

        • Why take my answer and give it away? What's the catch? - humster_spb pm
        • Why incite me? - Lyuba Ivanova 2:53 pm
        • In the sense - "incite"? - humster_spb
        • @LyubaIvanova, you really have a very similar answer, given an hour later than another. Can you clarify the situation? In essence, this, it seems, is not prohibited, but is not encouraged, especially by other participants) - Yuriy SPb pm