0

Верстаю соц сеть. Не удается сделать всплывающую подсказку при наведении на кнопку "...". Сам toolpit добавил прямо в кнопку. Но если сделать toolpit невидимым, то при наведении на кнопку, всплывающая подсказка не появляется. Как это сделать правильно?

.fanpage {
  background: #ffffff;
  box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  margin-top: 16px;
  padding: 10px 16px 16px 16px;
  margin-left: 24px;
}

.fanpage-header {
  display: flex;
  justify-content: space-between;
}

.fanpage-title {
  font-size: 14px;
  line-height: 22px;
  color: #595959;
  margin: 0;
  margin-bottom: 16px;
}

.post-header-button {
  background-color: white;
  border: none;
  display: flex;
}

.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
  /* visibility: hidden; */
  width: 63px;
  height: 32px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 4px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  bottom: 15px;
  margin-left: -45px;
}

.tooltiptext {
  font-style: normal;
  font-weight: 400;
  font-size: 14px;
  line-height: 22px;
  color: #FFFFFF;
}

.tooltip .tooltiptext::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: black transparent transparent transparent;
}

.tooltip:hover {
  visibility: visible;
}
<div class="fanpage">
  <div class="fanpage-header">
    <h4 class="fanpage-title">Your page</h4>
    <div class="funpage-dots">
      <button class="post-header-button">
                  <svg width="24" height="24" class="post-button-icon">
                    <use xlink:href="img/icons.svg#dots"></use>
                  </svg>
                  <div class="tooltip">
                    
                  <span class="tooltiptext">Options</span>
                  </div>
                </button></div>

  </div>

введите сюда описание изображения

2 ответа 2

1

Доброй ночи.

* { 
   box-sizing: border-box;
} 

body { 
   margin: 0; 
   padding: 0;  
   background-color: #fff;
}  

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

.toolpit .wrapper {  
  padding: 10px; 
} 

.toolpit__body {  
  position: relative;
  border: 1px solid transparent;
}

.toolpit-menu-link {    
  display: flex; 
  align-items: center; 
  justify-content: center; 
  margin: 130px 0 0 0;
  padding: 10px; 
  text-decoration: none; 
  font-size: 22px;  
  color: #000;  
  border-radius: 3px;
  background-color: silver;
}  

.toolpit__effect { 
   position: absolute;  
   left: 0;
   top: 0;  
   width: 100%; 
   height: 100%;   
   visibility: hidden;
   opacity: 0;
   transition: 0.2s;
} 

.btn {   
   position: absolute;
   cursor: pointer; 
   left: 50%; 
   top: 0;   
   transform: translate(-50%, 0); 
   margin: 30px 0; 
   font-size: 22px; 
   color: #000; 
   transition: 0.2s;
} 

.toolpit-menu-link:hover .toolpit__effect  {   
  visibility: visible;
  opacity: 1;
} 

.toolpit-menu-link:hover .toolpit__effect .btn  {   
}
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>tol</title>
</head>
<body> 
  <div class="toolpit"> 
    <div class="wrapper"> 
      <div class="toolpit__body">
        <a class="toolpit-menu-link" href="#">  
          <div class="toolpit__effect"> 
            <button class="btn" type="button">Options</button>
          </div>
          <span class="toolpit__text">Hover</span>  
        </a>        
    </div> 
   </div>
  </div>
</body>
</html>

1

Вам нужно показываться когда вы наводите на элемент в котором есть тултип, а не на сам тултип, для этого псевдокласс :hover нужно вешать на родителя.

В вашем случае вот так:

.fanpage {
  background: #ffffff;
  box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  margin-top: 16px;
  padding: 10px 16px 16px 16px;
  margin-left: 24px;
}

.fanpage-header {
  display: flex;
  justify-content: space-between;
}

.fanpage-title {
  font-size: 14px;
  line-height: 22px;
  color: #595959;
  margin: 0;
  margin-bottom: 16px;
}

.post-header-button {
  background-color: white;
  border: none;
  display: flex;
}

.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 63px;
  height: 32px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 4px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  bottom: 15px;
  margin-left: -45px;
}

.tooltiptext {
  font-style: normal;
  font-weight: 400;
  font-size: 14px;
  line-height: 22px;
  color: #FFFFFF;
}

.tooltip .tooltiptext::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: black transparent transparent transparent;
}

.post-header-button:hover .tooltiptext {
  visibility: visible;
}
<div class="fanpage">
  <div class="fanpage-header">
    <h4 class="fanpage-title">Your page</h4>
    <div class="funpage-dots">
      <button class="post-header-button">
        <img src="//i.imgur.com/D8lvrQx.png">
        <div class="tooltip">
          <span class="tooltiptext">Options</span>
        </div>
      </button>
    </div>
  </div>
</div>

1
  • Большое спасибо) разобрался
    – Артур
    13 янв 2021 в 3:44

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.