<style type="text/css">
*{
margin:0;
padding:0;
}
div{
display:inline;
background-color:red;
}
</style>
<body>
<div>item1</div>
<div>item2</div>
</body>
複製代碼
運行結果以下:css
<body>
<div>item1</div><div>item2</div>
</body>
複製代碼
<style type="text/css">
*{
margin:0;
padding:0;
}
.box{
font-size:0;
}
.box div{
display:inline;
font-size:16px;
background-color:red;
}
</style>
<body>
<div class="box">
<div>item1</div>
<div>item2</div>
</div>
</body>
複製代碼
運行結果以下所示:bash
<style type="text/css">
*{
margin:0;
padding:0;
}
.box .item{
display:list-item;
list-style-position: inside;
}
</style>
<body>
<div class="box">
<div class="item">item-1</div>
<div class="item">item-2</div>
<div class="item">item-3</div>
</div>
</body>
複製代碼
運行結果以下:ide
<style type="text/css">
*{
margin:0;
padding:0;
}
.table{
display:table;
width:100%;
box-sizing:border-box;
border-collapse:collapse;
}
.table .row{
display:table-row;
}
.table .cell{
display: table-cell;
height:35px;
line-height:35px;
border:1px solid #dedede;
text-align:center;
}
.table .caption{
display: table-caption;
height:35px;
line-height: 35px;
text-align:center;
}
</style>
<body>
<div class="table">
<div class="caption">這是一個表格</div>
<div class="row">
<div class="cell">item1</div>
<div class="cell">item1</div>
<div class="cell">item1</div>
</div>
<div class="row">
<div class="cell">item2</div>
<div class="cell">item2</div>
<div class="cell">item2</div>
</div>
</div>
</body>
複製代碼
運行效果以下:ui
<style type="text/css">
*{
margin:0;
padding:0;
}
.box{
width:300px;
height:300px;
display:table;
border:1px solid #dedede;
margin:20px auto;
}
.box div{
display: table-cell;
vertical-align: middle;
}
.box div p{
width:100px;
height:100px;
line-height:100px;
margin:0 auto;
text-align: center;
background-color:pink;
}
</style>
<body>
<div class="box">
<div>
<p>table</p>
</div>
</div>
</body>
複製代碼
運行效果以下:spa