css中常⽤的⼏种⾃适应布局⼀、⽔平居中(使⽤text-align+inline-block)
代码:
<!DOCTYPE html>
<html>
<head>
<meta chart="utf-8">
<style>
.parent{
text-align:center;
background:red;
width:200px;
height:200px;
}
.child{
display:inline-block;
background:yellow;
width:100px;
height:100px;
}
</style>
</head>
<body>
<div class="parent">
<div class="child">
argumentative
金山翻译软件</div>
</div>
</body>
</html>
运⾏结果:
⼆、垂直居中(使⽤table-cell+vertical-align)
代码:
<style>
.parent{
display:table-cell;
vertical-align:middle;
background:red;
width:200px;
height:200px;
}
.child{
display:inline-block;significance
background:yellow;
width:100px;
height:100px;
}
</style>
</head>
<body>
<div class="parent">
<div class="child">
</div>
</div>
</body>
</html>
运⾏效果:
luckyguy
三、⽔平垂直居中(使⽤text-align+inline-block+table-cell+vetical-align)代码:
<style>
.parent{
text-align:center;
display:table-cell;
vertical-align:middle;
ctf是什么意思background:red;
width:200px;
height:200px;
}
.child{
display:inline-block;
background:yellow;
width:100px;
height:100px;
}
</style>
</head>
<body>
<div class="parent">
<div class="child">
</div>
freestyle是什么意思
</div>
</body>
</html>
运⾏效果:
四、多列布局
(1)定宽+⾃适应(使⽤float+margin)代码:
<style>
.left{
background-color:red;
width:100px;
float:left;
高考英语作文常用句型
position:relative;
}
.rightfix{
background-color:blue;法硕考研培训
float:right;
margin-left:-100px;
width:100%;
}
.right{
margin-left:120px;
}
</style>
</head>
<body>
<div class="left">left</div>
<div class="rightfix">
<div class="right">
<p>right</p>
<p>right</p>exact
</div>
</div>
</body>
</html>
运⾏结果:
(2)两列定宽+⼀列⾃适应(使⽤float+overflow)代码:
<style>
.left{
background-color:red;
}
.center{
background-color:yellow;
}
.
left,.center{compod
width:100px;
float:left;
margin-right:20px;
}
.right{
overflow:hidden;
background-color:blue;
}
</style>
</head>
<body>
<div class="left">left</div>
<div class="center">center</div>
<div class="right"><p>right</p><p>right</p></div>
</body>
</html>
运⾏结果:
(3) 不定宽+⾃适应(使⽤float+overflow)代码: