CSS Flex 实现 Alignment Shifting Wrapping

2022-05-07 19:32:35 浏览数 (1)

实现效果:

1、用 float 实现

.html:
代码语言:javascript复制
<h3 class="title float-title">
  <span class="title-main">Main Title Here</span>
  <span class="title-note">This subtitle is floated.</span>
</h3>
.css:
代码语言:javascript复制
.title {
  border-bottom: 1px solid #ccc;
  margin: 40px auto;
}
.title-note {
  font-size: 60%;
  color: #999;
}

.float-title {
  .title-note {
    float: right;
    position: relative;
    top: 12px;
  }
}

2、用 flex 实现

.html:
代码语言:javascript复制
<h3 class="title flex-title">
  <span class="title-main">Main Title Here</span>
  <span class="title-note">This is a good look, right here.</span>
</h3>
.css:
代码语言:javascript复制
.title {
  border-bottom: 1px solid #ccc;
  margin: 40px auto;
}
.title-note {
  font-size: 60%;
  color: #999;
}

.flex-title {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  .title-main {
    flex-grow: 1;
  }
}

0 人点赞