如圖所示: display: inline 1 <div class="text1">文字一</div> 2 <div class="text2">文字二</div> 1 .text1,.text2{ 2 display: inline; 3 } display: inline-block 1 <div class="content1"></div> 2 <div class="content2"></div> 1 .content1,.content2{ 2 width: 200px; 3 height: 200px; 4 display: inline-block; 5 } 6 .content1{ 7 background-color: #008B8B; 8 } 9 .content2{ 10 background-color: #A0522D; 11 } 用display:inline-block可以讓元素在一行顯示但是它會受空格換行鍵的影響會產(chǎn)生默認(rèn)的間距; 1 <div class="wrap"> 2 <div class="box1">文字內(nèi)容一</div> 3 <div class="box2">文字內(nèi)容二</div> 4 </div> 1 .wrap{ 2 font-size: 0; 3 display: inline; 4 } 5 .box1,.box2{ 6 width: 200px; 7 height: 200px; 8 display: inline-block; 9 *display: inline;/*css hack ie瀏覽器可識別*/ 10 *zoom:1;/*觸發(fā)css hack的layout*/ 11 font-size: 16px; 12 } display: inline-block;在IE6,IE7下不兼容的解決辦法(css hack 兼容) =>*display: inline; =>*zoom:1; 總結(jié)讓多個元素在一行顯示面試題 1 <div class="main"> 2 <div class="left"></div> 3 <div class="right"></div> 4 </div> 1 .left,.right{ 2 width: 200px; 3 height: 200px; 4 float: left; 5 } 6 .left{ 7 background-color: #FF0000 8 } 9 .right{ 10 background-color: greenyellow 11 } 12 .main{ 13 overflow: hidden; 14 } 3.利用float:left/right,但是我們需要清除浮動,父集加下overflow:hidden 關(guān)于"display:inline-block兼容ie6/7的寫法"補充網(wǎng)址https://blog.csdn.net/ac601458466/article/details/48850669
|
|