Skip to content
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

任务八:如何实现左侧宽度固定,右侧宽度自适应的布局 #9

Open
zengkaiz opened this issue Apr 21, 2020 · 3 comments
Labels
CSS css相关任务

Comments

@zengkaiz
Copy link
Collaborator

No description provided.

@zengkaiz zengkaiz changed the title 如何实现左侧宽度固定,右侧宽度自适应的布局 任务八:如何实现左侧宽度固定,右侧宽度自适应的布局 Apr 21, 2020
@Mopecat Mopecat added the CSS css相关任务 label Apr 21, 2020
@LB-nan
Copy link
Collaborator

LB-nan commented Apr 21, 2020

html

<div class="box">
        <div class="left"></div>
        <div class="right"></div>
    </div>
.box {
            width: 100%;
            height: 400px;
        }
        
        .left {
            width: 200px;
            height: 400px;
            background: red;
            position: absolute;
        }
        
        .right {
            width: calc(100% - 200px);
            height: 100%;
            background: green;
            margin-left: 200px;
        }
.box {
            width: 100%;
            height: 400px;
            display: flex;
        }
        
        .left {
            width: 200px;
            height: 100%;
            background: red;
        }
        
        .right {
            width: calc(100% - 200px);
            height: 100%;
            background: green;
        }
.box {
            width: 100%;
            height: 400px;
        }
        
        .left {
            width: 200px;
            float: left;
            height: 100%;
            background: red;
        }
        
        .right {
            height: 100%;
            background: green;
            margin-left: 200px;
        }

@zengkaiz
Copy link
Collaborator Author

zengkaiz commented Apr 21, 2020

楼上第一种做法.right里面的width应该写多了吧。
.content {
height: 200px;
text-align: left;
}
.left{
width: 200px;
background: red;
position: absolute;
/* float: left; */
}
.right{
background: green;
margin-left: 200px;
}
将position:absolute改成 float:left也可以

@zengkaiz
Copy link
Collaborator Author

zengkaiz commented Apr 21, 2020

  1. 左边float + 右边overflow ;
  2. 左边float 或者 position + 右边margin ;
  3. 父display:felx + 右边flex:1 ;
    4.左边float + 右边calc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS css相关任务
Projects
None yet
Development

No branches or pull requests

3 participants