九热精品I亚洲电影第一页avI精品在线播放I成人av在线影视I日韩中文字幕视频在线观看I97精品国产一二三产区I色干综合

display:inline-block 去除間隙

2016/12/2 8:35:14   閱讀:1921    發布者:1921

先寫出代碼


核心css代碼:

.sample0{display: inline-block;height: 40px;width: 40px;color: #ffffff;
background-color: red; text-align: center;font-size: 26px;} .sample1{display: inline-block;height: 40px;width: 40px;color: #ffffff;
background-color: orange;text-align: center;font-size: 26px; .sample2{display: inline-block;height: 40px;width: 40px;color: #ffffff;
background-color: blue;text-align: center;font-size: 26px;}

核心html代碼:

<div class="sample0">0</div> 
<div class="sample1">1</div> 
<div class="sample2">2</div>

 

 

 

問題: display:inline-block的塊之間,有空隙


 

原因:換行顯示或空格分隔

 

解決方案一:margin 設置負值

核心 css 代碼

.sample0{display: inline-block;height: 40px;width: 40px;color: #ffffff;
background-color: red; text-align: center;font-size: 26px;margin-right: -4px;} .sample1{display: inline-block;height: 40px;width: 40px;color: #ffffff;
background-color: orange;text-align: center;font-size: 26px;margin: 0;margin:0 -4px;} .sample2{display: inline-block;height: 40px;width: 40px;color: #ffffff;
background-color: blue;text-align: center;font-size: 26px;margin-left: -4px;}

 

解決方案二: 將html元素寫緊湊(消除空格)

核心 html 代碼

<div class="sample0">0</div><div class="sample1">1</div><div class="sample2">2</div>