Giter VIP home page Giter VIP logo

inline-block-problem's Introduction

当我们用inline-block代替float的时候,会出现元素之间有空隙的情况,如图

这里写图片描述

再这里我就列举几种简单的办法:

1、元素之间出现空隙是因为标签段之间的空格,所以只要去掉标签端之间的空格即可。

//结构一
<div class="body" >
			<div class="box">	
			</div><div class="box">
			</div><div class="box">
			</div><div class="box">
			</div><div class="box">
			</div>
		</div>
//结构二
<div class="body" >
			<div class="box"></div
			><div class="box"></div
			><div class="box"></div
			><div class="box"></div
			><div class="box"></div>
		</div>
//结构三
<div class="body" >
			<div class="box"></div><!--
			--><div class="box"></div><!--
			--><div class="box"></div><!--
			--><div class="box"></div><!--
			--><div class="box"></div>
		</div>

2、子元素设置margin:-4px; 这种解决方法并不完美,如果你的父元素设置的字号不一样,可能你的“-4px”就不能解决问题。况且在Chrome中你需要设置margin:-8px;才能实现同等的效果。

.box{
	width: 50px;
	height: 50px;
	display: inline-block;
	background: lightcoral;
	margin: 0 auto;
	margin-right:-8px;
}

3、设置父元素字体为 0 。

.body{
	width: 300px;
	font-size: 0;
     /*-webkit-text-size-adjust:none;*/
	background: lightblue;
}

4、用浮动的方法也可以解决。

暂时就写这些以后遇到再慢慢补充。

inline-block-problem's People

Contributors

newbie-xidu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.