-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
一些常见的CSS面试问题 #15
Labels
Comments
左列定宽,右列自适应(1)利用float+margin实现 <style>
.left {
background-color: #f00;
float: left;
width: 100px;
height: 500px;
}
.right {
background-color: #0f0;
height: 500px;
margin-left: 100px; /*大于等于#left的宽度*/
}
</style>
<body>
<div class="left">左列定宽</div>
<div class="right">右列自适应</div>
</body> (2)利用float+margin(fix)实现 <style>
.left {
background-color: #f00;
float: left;
width: 100px;
height: 500px;
}
.right-fix {
float: right;
width: 100%;
margin-left: -100px; /*正值大于或等于#left的宽度,才能显示在同一行*/
}
.right{
margin-left: 100px; /*大于或等于#left的宽度*/
background-color: #0f0;
height: 500px;
}
</style>
<body>
<div class="left">左列定宽</div>
<div class="right-fix">
<div class="right">右列自适应</div>
</div>
</body> (3)使用float+overflow实现 <style>
.left {
background-color: #f00;
float: left;
width: 100px;
height: 500px;
}
.right {
background-color: #0f0;
height: 500px;
overflow: hidden; /*触发bfc达到自适应*/
}
</style>
<body>
<div class="left">左列定宽</div>
<div class="right">右列自适应</div>
</body> (4)使用table实现 <style>
.parent{
width: 100%;
display: table;
height: 500px;
}
.left {
width: 100px;
background-color: #f00;
}
.right {
background-color: #0f0;
}
.left,.right{
display: table-cell; /*利用单元格自动分配宽度*/
}
</style>
<body>
<div class="parent">
<div class="left">左列定宽</div>
<div class="right">右列自适应</div>
</div>
</body> (5)使用绝对定位实现 <style>
.parent{
position: relative; /*子绝父相*/
}
.left {
position: absolute;
top: 0;
left: 0;
background-color: #f00;
width: 100px;
height: 500px;
}
.right {
position: absolute;
top: 0;
left: 100px; /*值大于等于.left的宽度*/
right: 0;
background-color: #0f0;
height: 500px;
}
</style>
<body>
<div class="parent">
<div class="left">左列定宽</div>
<div class="right">右列自适应</div>
</div>
</body> (6)使用flex实现 <style>
.parent{
width: 100%;
height: 500px;
display: flex;
}
.left {
width: 100px;
background-color: #f00;
}
.right {
flex: 1; /*均分了父元素剩余空间*/
background-color: #0f0;
}
</style>
<body>
<div class="parent">
<div class="left">左列定宽</div>
<div class="right">右列自适应</div>
</div>
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
display有哪些值?说明他们的作用。
介绍一下标准的CSS的盒子模型?低版本IE的盒子模型有什么不同的?
如何居中div?
水平居中:给div设置一个宽度,然后添加margin:0 auto属性
让绝对定位的div居中
水平垂直居中一
水平垂直居中二
水平垂直居中三
将多个元素设置为同一行?清除浮动有几种方式?
The text was updated successfully, but these errors were encountered: