我为我的广告编写了工具提示,其中包含很多行话 - 它们只需将鼠标悬停在上方即可显示。显然,它们不适用于触摸界面。
我仅限于理想的纯 HTML5 和 CSS3,绝对没有 jquery,最好没有 javascript。我试过更改(或者更确切地说是添加):active 到 :hover 类,但在触摸屏上根本没有任何反应。
当前的 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;
}
<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>
CSS 中有一些动画和技巧(我没有包括链接帮助动画,但你明白了)基本上当你将鼠标悬停在它上面时,框会淡入淡出 - 还有一个完整的屏幕白色背景逐渐淡入,有点不透明,使鼠标悬停的框成为焦点 - 如果这不会发生在触摸屏设备上,这没什么大不了的。
我怀疑可能需要进行实质性更改才能在触摸屏设备上按下相同的弹出框。
最佳答案
是的,有办法。
首先:将属性“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;
}
<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>
关于html - 我的工具提示可以适用于触摸屏吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37148225/