css - div 與 inline block 空隙?
PHP中文网
PHP中文网 2017-04-17 11:59:34
0
8
650

想問問假設

<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中文网

认证高级PHP讲师

reply all(8)
阿神

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

左手右手慢动作
  .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之间的空格试试
Peter_Zhu

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.

伊谢尔伦

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;}
阿神

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>
大家讲道理

Float

.layoutp {
  float: left;
}
PHPzhong

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

洪涛

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!