我的工具提示可以适用于触摸屏吗?

Dan*_*erd 7 html css html5 css3

我已经为我的广告制作了一些工具提示,这些工具提供了大量的行话 - 他们用简单的鼠标显示.显然它们不适用于触摸界面.

我只限于理想的纯HTML5和CSS3,绝对没有jquery,理想情况下没有javascript.我尝试过更改(或者更确切地说):激活到:悬停类,但触摸屏上什么也没发生.

当前的HTML和CSS是

.tiptext {
  cursor: help;
  color: black;
  font-family: 'ProximaNova', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;
  font-weight: 600 !important;
  border-bottom: 1px solid #ebebeb;
  box-shadow: inset 0 -5px 0 #ebebeb;
  -webkit-transition: background .15s cubic-bezier(.33, .66, .66, 1);
  transition: background .15s cubic-bezier(.33, .66, .66, 1);
  text-decoration: none;
  font-size: 14px;
  line-height: 172%;
  -webkit-animation-name: link-helpoff;
  -webkit-animation-duration: 1s;
  animation-name: link-helpoff;
  animation-duration: 1s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
  transition-delay: 0.4s;
}
.tiptext::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  color: transparent;
  background-color: transparent;
  transition: background-color 0.5s linear;
}
.tiptext:hover::after {
  background-color: rgba(255, 255, 255, 0.6);
}
.description {
  border: 1px solid #e3e3e3;
  background: white;
  width: auto;
  max-width: 275px;
  height: auto;
  padding: 10px;
  font-family: 'ProximaNova', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;
  font-weight: 300;
  color: rgb(39, 44, 45);
  font-size: 13px;
  z-index: 500;
  position: absolute;
  margin-left: 50px;
  margin-top: 20px;
  cursor: default;
  display: inline-block;
}
.tiptext > .description {
  visibility: hidden;
  opacity: 0;
  transition: visibility 0s linear 0.4s, opacity 0.4s linear;
}
.tiptext:hover > .description {
  visibility: visible;
  opacity: 1;
  transition-delay: 0s;
  -webkit-transition: opacity 0.2s ease-in;
  -moz-transition: opacity 0.2s ease-in;
  -ms-transition: opacity 0.2s ease-in;
  -o-transition: opacity 0.2s ease-in;
  transition: opacity 0.2s ease-in;
}
.tiptext:hover {
  color: black;
  -webkit-animation-name: link-help;
  -webkit-animation-duration: 0.6s;
  animation-name: link-help;
  animation-duration: 0.6s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
  transition-delay: 0s;
}
Run Code Online (Sandbox Code Playgroud)
<span class="tiptext">
  <span class="description" style="text-align:center;">You can read more about the topic in this pop up box</span>
  Mouse over me to learn more.
</span>
Run Code Online (Sandbox Code Playgroud)

在CSS中有一些动画和技巧(我没有包含链接帮助动画,但你明白了)基本上当你将鼠标放在它上面时框会淡入淡出 - 并且还有一个全屏白色背景如果在触摸屏设备上没有发生这种情况,那么它就会变得有点不透明,从而使得整个盒子成为焦点.

我怀疑可能需要进行大量更改才能在触摸屏设备上按下相同的弹出框.

hal*_*web 5

是的,有办法。

首先:将属性“ontouchstart”添加到您的按钮。第二:添加 :active、:focus 和 :hover 的样式。

我已经在 iOS 上测试过它并且有效。(还没有在 Android 上尝试过)。

div {
  display: none;
}
button {
  width: 200px;
  height: 50px;
  border: 1px solid red;
  display: inline-block;
  
}
button:active,
button:focus,
button: hover {
  background-color: blue;
}
button:active + div,
button:focus + div,
button:hover + div {
  display: block;
}
Run Code Online (Sandbox Code Playgroud)
<p>Hello</p>
<button ontouchstart>Activate</button>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit, ipsa, officiis! Est voluptatibus explicabo sed atque provident vel deleniti nulla quis, ipsa quas dolorum, dolorem cum possimus accusamus impedit nostrum!</div>
<p>Goodbye</p>
Run Code Online (Sandbox Code Playgroud)