search

Home  >  Q&A  >  body text

css - div 與 inline block 空隙?

想問問假設

<p class="layout">
<p class="layoutp">內容</p>
<p class="layoutp">內容</p>
<p class="layoutp">內容</p>
<p class="layoutp">內容</p>
<p class="layoutp">內容</p>
</p>
.layout
{
    width:100%;
    margin: 0 auto;
}
.layoutp
{
    cursor: pointer;
    position: relative;
    width: 50%;
    height: 100vh;
    display: inline-block;
    margin: 0;
}

這樣會讓p之間有空隙,於是導致他沒辦法一行兩個
他會跑到下面去......

PHP中文网PHP中文网2866 days ago689

reply all(8)I'll reply

  • 阿神

    阿神2017-04-17 12:01:34

    The easiest way to cause the

    newline character is to add layout to font-size:0, and there are really a lot of searches for this problem online, http://www.zhangxinxu.com/wor... Here There is one by Zhang Xinxu, you can check it out

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 12:01:34

      .layout
      {
          width:100%;
          margin: 0 auto;
          font-size:0;
      }
      .layoutp
      {
          cursor: pointer;
          position: relative;
          width: 50%;
          height: 100vh;
          display: inline-block;
          margin: 0;
         font-size: 14px;
      }
    或者去掉p之间的空格试试

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 12:01:34

    Thank you for the invitation.

    There will be gaps between

    inline-block elements because there will be line breaks between each element (referring to the layoutp elements of each <p> class). For specific solutions, see removing the gaps between inline-block elements. I won’t go into details about the N methods of spacing.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 12:01:34

    inline-block parses newlines into spaces - this was a problem seven or eight years ago. . You can find the solution on Baidu yourself
    Here’s an example

    .layout{font-size:0;}
    .layoutp{font-size:16px;}

    reply
    0
  • 阿神

    阿神2017-04-17 12:01:34

    White space characters.

    <p class="layout">
    <p class="layoutp">內容</p><p class="layoutp">內容</p><p class="layoutp">內容</p><p class="layoutp">內容</p><p class="layoutp">內容</p>
    </p>

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 12:01:34

    Float

    .layoutp {
      float: left;
    }

    reply
    0
  • PHPz

    PHPz2017-04-17 12:01:34

    Inline-block will have a spacing of 3-4px. It's own attributes. So if you want to have no gaps, you need to use the float attribute

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 12:01:34

    This is inline-block parsing newlines into spaces. . Generally we can solve the problem by setting the parent element font-size:0

    reply
    0
  • Cancelreply