Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

html - Why images makes a gap around?

I'd like to ask, why there is a gap around the images. Is there something about this behaviour in the specification?

Simple code where you can see the gap between images:

<style>img {width: 100px; height: 100px; background: red;}</style>    

<img><br>
<img><br>
<img>

http://jsfiddle.net/sfptspj0/

I know that there is more posibilities how to remove this gap:

  1. display: block;
  2. float
  3. vertical-align

But I want to know why there is the gap, not how to remove that.

Any ideas?
Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If an image is displayed inline, it leaves a slight space below it. This is because the image is placed on the baseline of the text, and below the baseline there should be some more space for the descender characters like g, j or q.

Source: http://www.schoonzie.com/rogue-padding-below-images


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...