zoukankan      html  css  js  c++  java
  • css表示导航栏当前活动状态的箭头的几种方法

    例如lofter导航栏的箭头:

    方法:用一个块,宽高设置为0,再设置框的宽度(border)需要箭头向上时候,就设置下边框宽度,其他方向同理,这样便可得到一个箭头形状的小块,再设置颜色位置即可。

    <i class="arrow"></i>
    .arrow{
        display:inline-block;
        width:0;
        height:0;
        border:5px solid transparent;
        border-top:none;
        border-bottom-color:#FFF;
    }

    接下来讲箭头线条而并非箭头块:可以使用before和after伪元素来设置,这里就要用到两个伪元素块。也是通过设置他们的框宽差异来实现,

    <div id="test"></div>
    #test{
            height: 100px;
            width: 100px;
            border: 2px solid #000;
            position: relative;
          }
          #test:before,#test:after{
            border: solid transparent;
            content: ' ';
            height: 0;
            left: 100%;
            position: absolute;
            width: 0;
          }
          #test:after{
            border-width: 10px;
            border-left-color: #fff;
            top: 20px;
          }
          #test:before{
            border-width: 12px;
            border-left-color: #000;
            top: 18px;
          }

    箭头向右时如上代码;箭头向左时right:100%;before和after的boder-left-color改为boder-right-color;

    如果需要箭头为上下方向则可以用两个i标签,用大的i标签包含小的i标签通过颜色差异显示出来;代码如下:

    <div id="test"><i class="arrow"><i class="arrow2"></i></i></div>
    #test{
            /*background-color: green;*/
            height: 100px;
            width: 100px;
            border: 2px solid #000;
            position: relative;
          }
          #test:before,#test:after{
            border: solid transparent;
            content: ' ';
            height: 0;
            right: 100%;
            position: absolute;
            width: 0;
          }
          #test:after{
            border-width: 10px;
            border-right-color: #fff;
            /*border-left-color: green;*/
            top: 20px;
          }
          #test:before{
            border-width: 12px;
            border-right-color: #000;
          /*  border-left-color: green;*/
            top: 18px;
          }
    
          .arrow{
            display:inline-block;
            width:0;
            height:0;
            border:12px solid transparent;
            border-top:none;
            border-bottom-color:#000;
            top: -12px;
            position: absolute;
            margin-left: 40%;
          }
          .arrow2{
            display:inline-block;
            width:0;
            height:0;
            border:12px solid transparent;
            border-top:none;
            border-bottom-color:#fff;
            top: 3px;
            right: -12px;
            position: absolute;
          }
          .arrow-down{
            display:inline-block;
            width:0;
            height:0;
            border:12px solid transparent;
            border-bottom:none;
            border-top-color:#000;
            bottom: -12px;
            position: absolute;
            margin-left: 40%;
          }
          .arrow2-down{
            display:inline-block;
            width:0;
            height:0;
            border:12px solid transparent;
            border-bottom:none;
            border-top-color:green;
            bottom: 3px;
            right: -12px;
            position: absolute;
          }

    此图的向左箭头是用的伪元素方法,向上的箭头是用的 i 标签方法。

  • 相关阅读:
    日报11.1
    CCC2020 Surmising a Sprinter's Speed
    3D扫雷 (3D Minesweeper)
    如何使用小米手环与PN532(或类似芯片)复制验证卡号的IC卡
    分享一个api:随机二次元图片
    NOIP2017 时间复杂度 大模拟
    《区块链100问》笔记整理——42~49问
    Coursera-AndrewNg(吴恩达)机器学习笔记——第四周编程作业(多分类与神经网络)
    Coursera-AndrewNg(吴恩达)机器学习笔记——第四周
    《区块链100问》笔记整理——23~41问
  • 原文地址:https://www.cnblogs.com/Decmber/p/5254522.html
Copyright © 2011-2022 走看看