css3悬停在图标和边框上

时间:2014-07-18 21:12:12

标签: javascript html css css3

HTML CODE ...

          <ul class="social-icon">
            <li><a href="#" class="social-facebook">
            <i class="fa fa-facebook"></i>
            <i class="fa fa-facebook ff"></i>
            </a></li>
            <li><a href="#" class="social-twitter"><i class="fa fa-twitter"></i></a></li>
            <li><a href="#" class="social-google-plus"><i class="fa fa-google-plus"></i></a></li>
            <li><a href="#" class="social-dribbble"><i class="fa fa-dribbble"></i></a></li>
            <li><a href="#" class="social-linkedin"><i class="fa fa-linkedin"></i></a></li>
            <li><a href="#" class="social-rss"><i class="fa fa-rss"></i></a></li>
          </ul>

和CSS CODE ..

.social-icon {
      text-align: center;
      text-decoration: none;
    }
    .social-icon li {
      list-style: none;
      display: inline-block;
      float: left;
      position: relative;
    }
    .social-icon li a {
      display: inline-block;
      font-size: 18px;
      line-height: 28px;
      width: 35px;
      text-decoration: none;
      outline: none;
      height: 36px;
      border: 1px solid #000;
      border-top: 1px solid #000;
      border-bottom: 1px solid #000;
    }
    .social-icon li a:first-child {
      border-left: 1px solid #000;
    }
    .social-icon li a .ff {
      opacity: 0;
      -webkit-transform: scale(5);
      -moz-transform: scale(5);
      -o-transform: scale(5);
      -ms-transform: scale(5);
      transform: scale(5);
      -webkit-transition: all 0.3s ease-in-out 0.2s;
      -moz-transition: all 0.3s ease-in-out 0.2s;
      -o-transition: all 0.3s ease-in-out 0.2s;
      -ms-transition: all 0.3s ease-in-out 0.2s;
      transition: all 0.3s ease-in-out 0.2s;
    }
    .social-icon li a .ff:hover {
      opacity: 1;
      background-color: #345599;
      -webkit-transform: scale(1);
      -moz-transform: scale(1);
      -o-transform: scale(1);
      -ms-transform: scale(1);
      transform: scale(1);
      -webkit-transition-delay: 0.2s;
      -moz-transition-delay: 0.2s;
      -o-transition-delay: 0.2s;
      -ms-transition-delay: 0.2s;
      transition-delay: 0.2s;
    }
    .social-icon li a i {
      color: #d2d2db;
      position: absolute;
      top: 10px;
      left: 10px;
    }

问题是当我将鼠标悬停在fb图标上时,它的背景颜色很少。边界是双倍我用1px边框..请帮帮我...抱歉我的英文不好。

Here is jsFiddle editor link

4 个答案:

答案 0 :(得分:0)

我认为你需要做类似的事情:

.social-icon li a .ff:hover
{
    display: block; 
    width: 37px; 
    height: 32px;
}

.social-icon li a i
{
    left: 0;
    top: 0;
    color: #d2d2db;
    position: absolute
}

答案 1 :(得分:0)

这是什么意思?将您的CSS更改为以下内容......

.social-icon {
  text-align: center;
  text-decoration: none;
}
.social-icon li {
  list-style: none;
  display: inline-block;
  float: left;
  position: relative;
}
.social-icon li a {
  display: inline-block;
  font-size: 18px;
  line-height: 28px;
  width: 35px;
  text-decoration: none;
  outline: none;
  height: 36px;
  border: 1px solid #000;
  border-top: 1px solid #000;
  border-bottom: 1px solid #000;
}

.social-icon li :hover{
  background-color: #345599;
  -webkit-transition-delay: 0.2s;
  -moz-transition-delay: 0.2s;
  -o-transition-delay: 0.2s;
  -ms-transition-delay: 0.2s;
  transition-delay: 0.2s;
  -webkit-transition: all 0.3s ease-in-out 0.2s;
  -moz-transition: all 0.3s ease-in-out 0.2s;
  -o-transition: all 0.3s ease-in-out 0.2s;
  -ms-transition: all 0.3s ease-in-out 0.2s;
  transition: all 0.3s ease-in-out 0.2s;
}

.social-icon li a:first-child {
  border-left: 1px solid #000;
}
.social-icon li a .ff {
  opacity: 0;
  background-color: rgba(255, 255, 255, 0.0);
  -webkit-transform: scale(5);
  -moz-transform: scale(5);
  -o-transform: scale(5);
  -ms-transform: scale(5);
  transform: scale(5);
  -webkit-transition: all 0.3s ease-in-out 0.2s;
  -moz-transition: all 0.3s ease-in-out 0.2s;
  -o-transition: all 0.3s ease-in-out 0.2s;
  -ms-transition: all 0.3s ease-in-out 0.2s;
  transition: all 0.3s ease-in-out 0.2s;
}
.social-icon li a .ff:hover {
  opacity: 1;
  background-color: rgba(255, 255, 255, 0.0);
  -webkit-transform: scale(1);
  -moz-transform: scale(1);
  -o-transform: scale(1);
  -ms-transform: scale(1);
  transform: scale(1);
  -webkit-transition-delay: 0.2s;
  -moz-transition-delay: 0.2s;
  -o-transition-delay: 0.2s;
  -ms-transition-delay: 0.2s;
  transition-delay: 0.2s;
}
.social-icon li a i {
  color: #d2d2db;
  position: absolute;
  top: 10px;
  left: 10px;
}

我添加了课程 .social-icon li:hover

我还将属性 background-color:rgba(255,255,255,0.0); 添加到班级 .social-icon li a .ff:hover

答案 2 :(得分:0)

我认为这更接近你想要的东西:

.social-icon {
  text-align: center;
  text-decoration: none;
}
.social-icon li {
  list-style: none;
  float: left;
  position: relative;
  height: 38px;
}
.social-icon li a{
  display: inline-block;
  font-size: 18px;
  line-height: 28px;
  width: 35px;
  text-decoration: none;
  outline: none;
  height: 36px;
  border-right: 1px solid #000;
  border-top: 1px solid #000;
  border-bottom: 1px solid #000;
}
.social-icon li:first-child {
  border-left: 1px solid #000;
}
.social-icon li .ff {
  opacity: 0;
  -webkit-transform: scale(5);
  -moz-transform: scale(5);
  -o-transform: scale(5);
  -ms-transform: scale(5);
  transform: scale(5);
  -webkit-transition: all 0.3s ease-in-out 0.2s;
  -moz-transition: all 0.3s ease-in-out 0.2s;
  -o-transition: all 0.3s ease-in-out 0.2s;
  -ms-transition: all 0.3s ease-in-out 0.2s;
  transition: all 0.3s ease-in-out 0.2s;
}
.social-icon li .ff:hover {
  opacity: 1;
  background-color: #345599;
  -webkit-transform: scale(1);
  -moz-transform: scale(1);
  -o-transform: scale(1);
  -ms-transform: scale(1);
  transform: scale(1);
  -webkit-transition-delay: 0.2s;
  -moz-transition-delay: 0.2s;
  -o-transition-delay: 0.2s;
  -ms-transition-delay: 0.2s;
  transition-delay: 0.2s;
}

.social-icon li a i {
  color: #d2d2db;
  position: absolute;
  padding: 10px;
  top: 0px;
  left: 0px;
}

.social-icon .fa-facebook {
    padding-right: 15px;
}

编辑:我更新了代码。仍然存在.ff对象比<li>容器大得多的问题。因此,您将在框外的空格中激活过渡。

答案 3 :(得分:0)

您的第一胎选择器不正确。它选择列表的每个元素。这就是你有双边界的原因。

您的背景悬停仅选择<i>而不是整个<a>。因此,它似乎很小。

这是你想要的吗?

http://jsfiddle.net/2N2YF/64/

HTML:

<ul class="social-icon">
    <li><a href="#" class="social-facebook">
          <i class="fa fa-facebook"></i>        
        </a>
    </li>

    <li>
        <a href="#" class="social-twitter">
            <i class="fa fa-twitter"></i>
        </a>
    </li>

    <li>
        <a href="#" class="social-google-plus">
            <i class="fa fa-google-plus"></i>
        </a>
    </li>

    <li>
        <a href="#" class="social-dribbble">
            <i class="fa fa-dribbble"></i>
        </a>
    </li>

    <li>
        <a href="#" class="social-linkedin">
            <i class="fa fa-linkedin"></i>
        </a>
    </li>

    <li>
        <a href="#" class="social-rss">
            <i class="fa fa-rss"></i>
        </a>
    </li>

</ul>

CSS:

.social-icon {
  text-align: center;
  text-decoration: none;
}
.social-icon li {
  list-style: none;
  display: inline-block;
  float: left;
  position: relative;
}
.social-icon li a {
  display: inline-block;
  font-size: 18px;
  line-height: 28px;
  width: 35px;
  text-decoration: none;
  outline: none;
  height: 36px;
  border-right: 1px solid #000;
  border-top: 1px solid #000;
  border-bottom: 1px solid #000;
}
.social-icon li:first-child a {
  border-left: 1px solid #000;
}

/* Facebook colour */
.social-icon li a.social-facebook:hover {
    background-color: #345599;
}

.social-icon li a:hover {
  opacity: 1;
  -webkit-transform: scale(1);
  -moz-transform: scale(1);
  -o-transform: scale(1);
  -ms-transform: scale(1);
  transform: scale(1);
  -webkit-transition-delay: 0.2s;
  -moz-transition-delay: 0.2s;
  -o-transition-delay: 0.2s;
  -ms-transition-delay: 0.2s;
  transition-delay: 0.2s;
}
.social-icon li a i {
  color: #d2d2db;
  position: absolute;
  top: 10px;
  left: 10px;
}