首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建社交媒体工具提示

创建社交媒体工具提示
EN

Stack Overflow用户
提问于 2019-02-07 02:49:25
回答 2查看 894关注 0票数 2

我已经把社交媒体图标放在我的页脚作为一个“跟随我”部分。现在我想要一个工具提示,这里是bottom,每个工具都会弹出一个文本"facebook“、"Twitter”等等。

我如何实现我已经拥有的,因为我不想搞砸我的页脚和我的社交媒体图标,而试图这样做。有办法挤进<span class="tooltiptext">吗?还是用这个作为身份标签?例如,我想尝试一下这样的方法。

代码语言:javascript
复制
<a href="#" class="fa fa-facebook" id="tooltiptext"></a>

这个是可能的吗?

任何技巧和技巧都将不胜感激。可以随意运行代码片段,看看我的社交媒体图标现在是什么样子。

代码语言:javascript
复制
/* Footer aka a copyright + social media pages */

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  text-align: center;
  /* Height of the footer */
  background-color: #b3b3ff;
}

.tooltip .tooltiptext {
  width: 120px;
  bottom: 100%;
  left: 50%;
  margin-left: -60px;
  /* Use half of the width (120/2 = 60), to center the tooltip */
}

.fa {
  padding: 20px;
  font-size: 30px;
  width: 50px;
  text-align: center;
  text-decoration: none;
  margin: 5px 2px;
  border-radius: 50%;
}

.fa:hover {
  opacity: 0.7;
}

.fa-facebook {
  background: #3B5998;
  color: white;
}

.fa-twitter {
  background: #55ACEE;
  color: white;
}

.fa-linkedin {
  background: #007bb5;
  color: white;
}

.fa-instagram {
  background: #125688;
  color: white;
}

.fa-snapchat {
  background: #fffc00;
  color: white;
  text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
代码语言:javascript
复制
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="footer">
  <div class="tooltip">

    <!-- Now where should I place "tooltiptext" -->

    <a href="#" class="fa fa-facebook"></a>
    <a href="#" class="fa fa-twitter"></a>
    <a href="#" class="fa fa-linkedin"></a>
    <a href="#" class="fa fa-instagram"></a>
    <a href="#" class="fa fa-snapchat"></a>
  </div>
</div>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-07 04:21:38

您应该在.tooltip中使用<a>,而不是.tooltiptext的父级<div>

代码语言:javascript
复制
.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  text-align: center;
  /* Height of the footer */
  background-color: #b3b3ff;
}

/* Tooltip container */
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
}

/* Tooltip text */
.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  padding: 5px 0;
  border-radius: 6px;
 
  /* Position the tooltip text - see examples below! */
  position: absolute;
 bottom: 100%;
  left: 50%; 
  margin-left: -60px; /* Use half of the width (120/2 = 60), to center the tooltip */
  z-index: 1;
}

/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
  visibility: visible;
}

.fa {
  padding: 20px;
  font-size: 30px;
  width: 50px;
  text-align: center;
  text-decoration: none;
  margin: 5px 2px;
  border-radius: 50%;
}

.fa:hover {
    opacity: 0.7;
}

.fa-facebook:hover .tooltiptext {
  background: #3B5998;
  color: white;
  visibility: visible;
}

.fa-twitter {
  background: #55ACEE;
  color: white;
}

.fa-linkedin {
  background: #007bb5;
  color: white;
}

.fa-instagram {
  background: #125688;
  color: white;
}

.fa-snapchat {
  background: #fffc00;
  color: white;
  text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
代码语言:javascript
复制
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Homepage</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link rel="stylesheet" type="text/css" href="main.css">
  <script src="script.js"></script>
</head>

<body>
  
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <div class="footer">
      <div>
        <!-- Now where should I place "tooltiptext" -->
        <a href="#" class="fa fa-facebook tooltip"><span class="tooltiptext">Facebook</span></a>
        <a href="#" class="fa fa-twitter tooltip"><span class="tooltiptext">Twitter</span></a>
        <a href="#" class="fa fa-linkedin tooltip"><span class="tooltiptext">Linkedin</span></a>
        <a href="#" class="fa fa-instagram tooltip"><span class="tooltiptext">Instagram</span></a>
        <a href="#" class="fa fa-snapchat tooltip"><><span class="tooltiptext">Snapchat</span></a>
      </div>
    </div>
  
</body>
</html>

票数 2
EN

Stack Overflow用户

发布于 2019-02-07 03:52:29

我尝试将以下内容添加到您的代码中并进行工作:

  1. 添加可见性:隐藏在css的工具提示中
代码语言:javascript
复制
.tooltip .tooltiptext {
 visibility: hidden;
 width: 120px;
 bottom: 100%;
 left: 50%;
 margin-left: -60px;
 /* Use half of the width (120/2 = 60), to center the tooltip */
}
  1. 在css中,每次悬停链接时都声明工具提示的可见性。尝试这样做,所有的链接,你有。
代码语言:javascript
复制
.fa-facebook:hover .tooltiptext {
 visibility: visible;
}
  1. 在html元素中添加带有tooltiptext的元素。
代码语言:javascript
复制
   <a href="#" class="fa fa-facebook">
       <span class="tooltiptext">Facebook</span>
    </a>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54565594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档