Flex布局

2019-11-27  本文已影响0人  fanison

四栏布局

    <ul class="nav">
      <li>Leading-Role</li>
      <li>Supporting-Role</li>
      <li>Team</li>
      <li>About</li>
    </ul>
.nav{
  display:flex;
  border:1px solid red;
}
.nav > li{
  padding: 4px 0.5em;
  margin-right: 10px;
  margin-top: 2px;
  font-size: 18px;
}

两栏布局

  <header class="header">
    <div class="logo">
      House of Cards
    </div>
    <ul class="nav">
      <li>Leading-Role</li>
      <li>Supporting-Role</li>
      <li>Team</li>
      <li>About</li>
    </ul>
  </header>
.nav{
  display:flex;
}
.nav > li{
  padding: 4px 0.5em;
  margin-right: 10px;
  margin-top: 2px;
  font-size: 18px;
}

.header{
  display:flex;
  justify-content:space-between;
  align-items:center; 
  /* border:1px solid green; */
  font-size: 20px;
  background: grey;
  color: white;
}
.logo{
   margin: 6px 20px;
}

三栏布局

    <div class="content">
      <aside></aside>
      <main></main>
      <div class="ad"></div>
    </div>
.content{
  display:flex;
  width:800px;
  margin-left:auto;
  margin-right:auto; 
}
.content > aside {
  width: 200px;
  height: 500px;
  background-color: rgb(255, 130, 160);
}
.content > main {
  width: 500px;
  background-color: green;
}
.content > .ad {
  width: 100px;
  background-color: purple;
}

平均布局

    <div class="imageList">
      <div class="x">
        <div class="image"></div>
        <div class="image"></div>
        <div class="image"></div>
        <div class="image"></div>
        <div class="image"></div>
        <div class="image"></div>
        <div class="image"></div>
      </div>
    </div>
.imageList{
  width:800px;
  margin-left:auto;
  margin-right:auto;
} 
.imageList > .x{
  display:flex;
  flex-wrap:wrap;
  margin-right:-20px;
}
.image{
  width: 185px;
  height: 185px;
  margin-bottom: 20px;
  margin-right: 20px;
  background-color: rgba(255, 0, 0, 0.3);
  border:1px solid green;
}

flex布局

.container{
  display:flex;/* inline-flex */   
}

flex-direction:定义主轴方向

flex-wrap:定义元素换行

justify-content:将flex元素和主轴对齐

align-items:在交叉轴上对齐多个元素

align-self:单个元素分布


align-content:多行元素分布

上一篇下一篇

猜你喜欢

热点阅读