你能创建一个css"功能"或包装

时间:2015-04-02 08:44:53

标签: html css

因此遇到了一些问题,并试图找出最佳方法。

所以得到了一些css代码(从编码器中借来的比我更好)在菜单中创建了一组漂亮的箭头,大量使用:after和:hover以及所有排序。不得不在另一个应用程序中编写它,现在想将它移动到实际的页面。

问题是,我需要设置课程,而我正在做一些非常错误的事情。基本上,我决定使用“arrowrt”类将其设置为顶部菜单。但是包装它的最简单方法是什么,或者包装它是否容易。想要做.arrowrt {加载CSS设置}

目前的代码如下

   <style type="text/css" media="all">

    a {
            text-decoration:none;
        }
    ul {
        margin: 20px 60px;
    }
    li {
        margin-right: 5px;
    }
    ul li {
        display: inline-block;
        font-size: 12px;
        height: 30px;
        line-height: 30px;
        width: 150px;
        margin: 5px 8px 0 0;
        text-align: center;
        position: relative;
    }

    ul li:before {
        content: " ";
        height: 0;
        width: 0;
        position: absolute;
        left: -2px;
        border-style: solid;
        border-width: 15px 0 15px 15px;
        border-color: transparent transparent transparent #fff;
        z-index: 0;
    }

     ul li:first-child:before , .dbfsrt {
        border-color: transparent;
    }
    ul li a:after {
        content: " ";
        height: 0;
        width: 0;
        position: absolute;
        right: -15px;
        border-style: solid;
        color: #000000;
        border-width: 15px 0 15px 15px;
        border-color: transparent transparent transparent #ccc;
        z-index: 10;
    }

    ul li.arractive a {
        background: orange;
        z-index: 100;
    }

    ul li.active a:after {
        border-left-color: orange;
    }

    ul li a {
        display: block;
        background: #ccc;
        color: #000000;
    }

    ul li a:hover {
        background: #000000;
        color: #ececec;
    }

    ul li a:hover:after {
        border-color: transparent transparent transparent #000000;

    }




</style>

HTML部分

<ul id="arrowrt">
    <li class="arrowrt"><a  href="#">Home</a></li>
    <li class="arrowrt"><a  href="#">Back Office</a></li>
    <li class="arrowrt"><a  href="#">Cash Management</a></li>
    <li class="arrowrt arractive"><a href="#">Overdraft Management</a></li>
</ul>

1 个答案:

答案 0 :(得分:3)

你可以(如果使用sass)做这样的事情:

.arrowrt li {
  display: inline-block;
  font-size: 12px;
  height: 30px;
  line-height: 30px;
  width: 150px;
  margin: 5px 8px 0 0;
  text-align: center;
  position: relative;
  &:before {
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    left: -2px;
    border-style: solid;
    border-width: 15px 0 15px 15px;
    border-color: transparent transparent transparent #fff;
    z-index: 0;
  }
  &:first-child:before {
    border-color: transparent;
  }
}

.dbfsrt {
  border-color: transparent;
}

.arrowrt li {
  a:after {
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    right: -15px;
    border-style: solid;
    color: #000000;
    border-width: 15px 0 15px 15px;
    border-color: transparent transparent transparent #ccc;
    z-index: 10;
  }
  &.arractive a {
    background: orange;
    z-index: 100;
  }
  &.active a:after {
    border-left-color: orange;
  }
  a {
    display: block;
    background: #ccc;
    color: #000000;
    &:hover {
      background: #000000;
      color: #ececec;
      &:after {
        border-color: transparent transparent transparent #000000;
      }
    }
  }
}

但你应该将arrowrt作为一个非id的类,以便可以重复使用。

这对应的css是:

.arrowrt li {
  display: inline-block;
  font-size: 12px;
  height: 30px;
  line-height: 30px;
  width: 150px;
  margin: 5px 8px 0 0;
  text-align: center;
  position: relative;
}
.arrowrt li:before {
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  left: -2px;
  border-style: solid;
  border-width: 15px 0 15px 15px;
  border-color: transparent transparent transparent #fff;
  z-index: 0;
}
.arrowrt li:first-child:before {
  border-color: transparent;
}

.dbfsrt {
  border-color: transparent;
}

.arrowrt li a:after {
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  right: -15px;
  border-style: solid;
  color: #000000;
  border-width: 15px 0 15px 15px;
  border-color: transparent transparent transparent #ccc;
  z-index: 10;
}
.arrowrt li.arractive a {
  background: orange;
  z-index: 100;
}
.arrowrt li.active a:after {
  border-left-color: orange;
}
.arrowrt li a {
  display: block;
  background: #ccc;
  color: #000000;
}
.arrowrt li a:hover {
  background: #000000;
  color: #ececec;
}
.arrowrt li a:hover:after {
  border-color: transparent transparent transparent #000000;
}