Web实现:微博底部栏实例

78 篇文章 2 订阅
68 篇文章 0 订阅

HTML部分:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" href="./index.css" />
    <title>移动端微博首页</title>
  </head>
  <body>
    <footer class="footer">
      <div class="item">
        <span class="icon home-icon"></span>
        <span class="txt">微博</span>
      </div>
      <div class="item">
        <img class="avatar-icon" src="./images/avatar.png" alt="" />
      </div>
      <div class="item">
        <span class="icon search-icon"></span>
        <span class="txt">发现</span>
      </div>
      <div class="item">
        <span class="icon mail-icon"></span>
        <span class="txt">消息</span>
      </div>
      <div class="item">
        <span class="icon mine-icon"></span>
        <span class="txt"></span>
      </div>
    </footer>
  </body>
</html>

CSS部分:

html,
body {
  height: 100%;
  margin: 0; }

ul,
li {
  margin: 0;
  padding: 0; }

li {
  list-style: none; }

h1,
h2 {
  margin: 0; }

p {
  margin: 0;
  padding: 0; }

@media screen and (max-width: 768px) {
  html {
    font-size: 20px; } }

@media screen and (max-width: 320px) {
  html {
    font-size: 17.0666666667px; } }

body {
  max-width: 768px;
  margin: 0 auto; }

footer.footer {
  max-width: 768px;
  margin: 0 auto;
  height: 2.4rem;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 1.5rem;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: #fff; }
  footer.footer .item {
    width: 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.55rem;
    line-height: 0.75rem;
    color: #000000;
    padding-bottom: 0.2rem; }
    footer.footer .item:nth-child(2) {
      align-self: center;
      padding-bottom: 0; }
    footer.footer .item .avatar-icon {
      width: 1.5rem;
      height: 1.5rem;
      border-radius: 50%; }
    footer.footer .item .home-icon {
      background: url(./images/home.png) no-repeat center/contain; }
    footer.footer .item .search-icon {
      background: url(./images/search.png) no-repeat center/contain; }
    footer.footer .item .mail-icon {
      background: url(./images/mail.png) no-repeat center/contain; }
    footer.footer .item .mine-icon {
      background: url(./images/mine.png) no-repeat center/contain; }
    footer.footer .item .home-icon {
      width: 1rem;
      height: 1.1rem;
      margin-bottom: 0.1rem; }
    footer.footer .item .search-icon {
      width: 1rem;
      height: 1.15rem; }
    footer.footer .item .mail-icon {
      width: 1.1rem;
      height: 0.85rem;
      margin-bottom: 0.2rem; }
    footer.footer .item .mine-icon {
      width: 1rem;
      height: 1rem;
      margin-bottom: 0.1rem;
      position: relative; }
      footer.footer .item .mine-icon::after {
        content: '';
        width: 0.3rem;
        height: 0.3rem;
        display: block;
        background: #FF3939;
        border-radius: 50%;
        position: absolute;
        top: -1px;
        right: -0.2rem; }

/*scss代码如下:*/
/*html,
body {
  height: 100%;
  margin: 0;
}

ul,
li {
  margin: 0;
  padding: 0;
}
li {
  list-style: none;
}

h1,
h2 {
  margin: 0;
}

p {
  margin: 0;
  padding: 0;
}

// 浏览器都有自己的默认样式,以上部分为清除浏览器默认样式

// 媒体查询
@media screen and (max-width: 768px) {
  html {
    font-size: 20px;
  }
}

@media screen and (max-width: 320px) {
  html {
    font-size: 20px / 375 * 320;
  }
}

// 尺寸处理自定义函数
// 移动端微博设计稿尺寸宽度为375,这里除以 20
@function px2rem($px) {
  @return #{$px / 20}rem;
}

// body部分最大宽度
$maxWidth: 768px;

body {
  max-width: $maxWidth;
  margin: 0 auto;
}

footer.footer {
  max-width: $maxWidth;
  margin: 0 auto;
  height: px2rem(48);
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 px2rem(30);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: #fff;

  .item {
    width: px2rem(30);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: px2rem(11);
    line-height: px2rem(15);
    color: #000000;
    padding-bottom: px2rem(4);
    &:nth-child(2) {
      align-self: center;
      padding-bottom: 0;
    }
    .avatar-icon {
      width: px2rem(30);
      height: px2rem(30);
      border-radius: 50%;
    }
    @each $icon in home, search, mail, mine {
      .#{$icon}-icon {
        background: url(./images/#{$icon}.png) no-repeat center / contain;
      }
    }
    .home-icon {
      width: px2rem(20);
      height: px2rem(22);
      margin-bottom: px2rem(2);
    }
    .search-icon {
      width: px2rem(20);
      height: px2rem(23);
    }
    .mail-icon {
      width: px2rem(22);
      height: px2rem(17);
      margin-bottom: px2rem(4);
    }
    .mine-icon {
      width: px2rem(20);
      height: px2rem(20);
      margin-bottom: px2rem(2);
      position: relative;
      &::after {
        content: '';
        width: px2rem(6);
        height: px2rem(6);
        display: block;
        background: #FF3939;
        border-radius: 50%;
        position: absolute;
        top: -1px;
        right: px2rem(-4);
      }
    }
  }
}*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在fragment实例中添加底部导航,可以使用Android官方提供的BottomNavigationView组件。首先在布局文件中添加BottomNavigationView组件,然后在fragment的onViewCreated方法中获取该组件并设置其菜单项和监听器。 示例代码如下: ```xml <android.support.design.widget.BottomNavigationView android:id="@+id/navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" app:menu="@menu/navigation_menu" /> ``` ```java public class MyFragment extends Fragment { private BottomNavigationView bottomNavigationView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_layout, container, false); bottomNavigationView = view.findViewById(R.id.navigation); return view; } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); bottomNavigationView.setOnNavigationItemSelectedListener( new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { // Handle navigation item clicks here. return true; } }); } } ``` 在代码中,我们先通过findViewById方法获取BottomNavigationView组件,然后在onViewCreated方法中设置监听器,当用户点击底部导航的菜单项时,onNavigationItemSelected方法会被调用。在该方法中,我们可以根据点击的菜单项来执行相应的操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jasmyn518

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值