display:inline-block解決文字有間隙問題
阿新 • • 發佈:2018-04-20
span ack white info IT play 高度 lock nbsp
定義:display:inline-block是使元素以塊級元素的形式呈現在行內。意思就是說,讓這個元素顯示在同一行不換行,但是又可以控制高度和寬度,這相當於內聯元素的增強。
但是display:inline-block存在文字間隙問題
- <div class="container">
- <div class="left">
- 左
- </div>
- <div class="right">
- 右
- </div>
- </div>
- .container{
- width:800px;
- height:200px;
- }
- .left
- {
- background:red;
- dispaly:inline-block;
- width:200px;
- height:200px;
- }
- .right
- {
- background:red;
- dispaly:inline-block;
- width:600px;
- height:200px;
- }
解決辦法:
父元素font-size=0 ,再向兩個子元素分別設置font-size
- .container{
- width:800px;
- height:200px;
- font-size:0;
- }
- .left{
- font-size:14px;
- background:red;
- display: inline-block;
- width:200px;
- height:200px;
- }
- .right{
- font-size:14px;
- background:blue;
- display: inline-block;
- width:600px;
- height:200px;
- }
display:inline-block解決文字有間隙問題