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

两栏布局 #2

Open
AILINGANGEL opened this issue May 30, 2019 · 0 comments
Open

两栏布局 #2

AILINGANGEL opened this issue May 30, 2019 · 0 comments

Comments

@AILINGANGEL
Copy link
Owner

<div class="div1"></div>
<div class="div2"></div>l

方法一: 利用BFC

  • float: left
  • overflow: hidden
.div1 {
  float: left; // 这里
  width: 300px;
  background-color: pink;
  height: calc(100vh - 100px);
}

.div2 {
  background-color: black;
  height: 100vh;
  overflow: hidden; // 这里
}

方法二: 利用float和margin

  • float: left
  • margin-left: float元素的宽度
.div1 {
  float: left; // 这里
  width: 300px;
  background-color: pink;
  height: calc(100vh - 100px);
}

.div2 {
  background-color: black;
  height: 100vh;
  margin-left: 300px; // 这里
}

方法三: 两个float + calc

  • float: left
  • float: left + width: calc(100% - 左侧float元素的宽度)
.div1 {
  float: left; //这里
  width: 300px;
  background-color: pink;
  height: calc(100vh - 100px);
}

.div2 {
  float: left; //这里
  background-color: black;
  height: 100vh;
  width: calc(100% - 300px); // 这里
}

方法四: 经典的flex

  • 父元素设置display:flex
  • 第一个子元素固定宽度width
  • 第二个子元素 flex-grow: 1 表示充满剩余的空间
// 这父元素
body {
  display: flex;
}
.div1 {
  width: 300px; // 
  background-color: pink;
  height: calc(100vh - 100px);
}

.div2 {
  flex-grow: 1; //这里
  background-color: black;
  height: 100vh;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant