Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用display:inline-block会产生什么问题?解决方法? #22

Open
conan1992 opened this issue Jun 17, 2020 · 0 comments
Open
Labels

Comments

@conan1992
Copy link
Owner

问题

两个display:inline-block元素放到一起会产生一段空白。

原因

在字体大小不为0的情况下,元素之间的空白符(空格、回车换行等)占据一定宽度;

解决办法

  • 设置父元素font-size为0,子元素再设置font-size
  • 给元素添加float;
  • 去掉回车,将子元素标签的结束符和下一个标签的开始符写在同一行或把所有子标签写在同一行
<div class="container">
  <div class="left"></div><div class="right"></div>
</div>
@conan1992 conan1992 added the CSS label Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant