Css : 只专注于 firefox。其他浏览器不支持
Css :focus working on firefox only. Other browser not supporting
我正在使用 html 和 css 创建聊天弹出窗口。我有一个可以显示和隐藏聊天图标的按钮。这是代码
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>floating button demo</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<style type="text/css">
*{padding:0;margin:0;}
body{
font-family:Verdana, Geneva, sans-serif;
background-color:#CCC;
font-size:12px;
}
.label-container{
position:fixed;
bottom:48px;
right:105px;
display:table;
visibility: hidden;
}
.label-text{
color:#FFF;
background:rgba(51,51,51,0.5);
display:table-cell;
vertical-align:middle;
padding:10px;
border-radius:3px;
}
.label-arrow{
display:table-cell;
vertical-align:middle;
color:#333;
opacity:0.5;
}
.float{
position:fixed;
width:60px;
height:60px;
bottom:40px;
right:40px;
background-color:#F33;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
z-index:1000;
}
ul{
position:fixed;
right:40px;
padding-bottom:20px;
bottom:80px;
z-index:100;
}
ul li{
list-style:none;
margin-bottom:10px;
}
ul li a{
background-color:#F33;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
width:60px;
height:60px;
display:block;
}
ul:hover{
visibility:visible!important;
opacity:1!important;
}
.my-float{
font-size:24px;
margin-top:18px;
}
a#menu-share i{
animation: rotate-in 0.5s;
}
a#menu-share:hover > i{
animation: rotate-out 0.5s;
}
@keyframes bot-to-top {
0% {bottom:-40px}
50% {bottom:40px}
}
@keyframes scale-in {
from {transform: scale(0);opacity: 0;}
to {transform: scale(1);opacity: 1;}
}
@keyframes rotate-in {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
@keyframes rotate-out {
from {transform: rotate(360deg);}
to {transform: rotate(0deg);}
}
a#menu-share + ul {
visibility: hidden;
}
a#menu-share:focus + ul{
visibility: visible;
animation: scale-in 0.5s;
}
a#menu-share:focus {
display: none;
}
</style>
</head>
<body>
<a href="javascript:void(0);" class="float" id="menu-close">
<i class="fa fa-times my-float"></i>
</a>
<a href="javascript:void(0);" class="float" id="menu-share">
<i class="fa fa-share my-float"></i>
</a>
<ul>
<li><a href="#" id="menu-facebook">
<i class="fa fa-facebook my-float"></i>
</a></li>
<li><a href="#" id="menu-google-plus">
<i class="fa fa-google-plus my-float"></i>
</a></li>
<li><a href="#" id="menu-twitter">
<i class="fa fa-twitter my-float"></i>
</a></li>
</ul>
</body>
</html>
该代码仅在 Firefox 上运行良好。我使用了 :focus css 并且它只在 firefox 上运行良好。其他浏览器未使用 :focus 打开弹出窗口。
我也制作了 jsfiddle,它在那里工作得很好。 https://jsfiddle.net/wtrx3gc9/
有人可以分享提示或帮助我使用 :focus 在所有浏览器上显示弹出窗口。
在 Chrome 中,当您给它 display: none
时,元素失去焦点。
解决方案:以另一种方式隐藏它,例如通过给它 z-index: 100;
(或任何小于关闭按钮的 z-index 的值)。
@import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css');
*{padding:0;margin:0;}
body{
font-family:Verdana, Geneva, sans-serif;
background-color:#CCC;
font-size:12px;
}
.label-container{
position:fixed;
bottom:48px;
right:105px;
display:table;
visibility: hidden;
}
.label-text{
color:#FFF;
background:rgba(51,51,51,0.5);
display:table-cell;
vertical-align:middle;
padding:10px;
border-radius:3px;
}
.label-arrow{
display:table-cell;
vertical-align:middle;
color:#333;
opacity:0.5;
}
.float{
position:fixed;
width:60px;
height:60px;
bottom:40px;
right:40px;
background-color:#F33;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
z-index:1000;
}
ul{
position:fixed;
right:40px;
padding-bottom:20px;
bottom:80px;
z-index:100;
}
ul li{
list-style:none;
margin-bottom:10px;
}
ul li a{
background-color:#F33;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
width:60px;
height:60px;
display:block;
}
ul:hover{
visibility:visible!important;
opacity:1!important;
}
.my-float{
font-size:24px;
margin-top:18px;
}
a#menu-share i{
animation: rotate-in 0.5s;
}
a#menu-share:hover > i{
animation: rotate-out 0.5s;
}
@keyframes bot-to-top {
0% {bottom:-40px}
50% {bottom:40px}
}
@keyframes scale-in {
from {transform: scale(0);opacity: 0;}
to {transform: scale(1);opacity: 1;}
}
@keyframes rotate-in {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
@keyframes rotate-out {
from {transform: rotate(360deg);}
to {transform: rotate(0deg);}
}
a#menu-share + ul {
visibility: hidden;
}
a#menu-share:focus + ul{
visibility: visible;
animation: scale-in 0.5s;
}
a#menu-share:focus {
/* display: none;*/
z-index: 100;
}
<a href="javascript:void(0);" class="float" id="menu-close">
<i class="fa fa-times my-float"></i>
</a>
<a href="javascript:void(0);" class="float" id="menu-share">
<i class="fa fa-share my-float"></i>
</a>
<ul>
<li><a href="#" id="menu-facebook">
<i class="fa fa-facebook my-float"></i>
</a></li>
<li><a href="#" id="menu-google-plus">
<i class="fa fa-google-plus my-float"></i>
</a></li>
<li><a href="#" id="menu-twitter">
<i class="fa fa-twitter my-float"></i>
</a></li>
</ul>
我正在使用 html 和 css 创建聊天弹出窗口。我有一个可以显示和隐藏聊天图标的按钮。这是代码
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>floating button demo</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<style type="text/css">
*{padding:0;margin:0;}
body{
font-family:Verdana, Geneva, sans-serif;
background-color:#CCC;
font-size:12px;
}
.label-container{
position:fixed;
bottom:48px;
right:105px;
display:table;
visibility: hidden;
}
.label-text{
color:#FFF;
background:rgba(51,51,51,0.5);
display:table-cell;
vertical-align:middle;
padding:10px;
border-radius:3px;
}
.label-arrow{
display:table-cell;
vertical-align:middle;
color:#333;
opacity:0.5;
}
.float{
position:fixed;
width:60px;
height:60px;
bottom:40px;
right:40px;
background-color:#F33;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
z-index:1000;
}
ul{
position:fixed;
right:40px;
padding-bottom:20px;
bottom:80px;
z-index:100;
}
ul li{
list-style:none;
margin-bottom:10px;
}
ul li a{
background-color:#F33;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
width:60px;
height:60px;
display:block;
}
ul:hover{
visibility:visible!important;
opacity:1!important;
}
.my-float{
font-size:24px;
margin-top:18px;
}
a#menu-share i{
animation: rotate-in 0.5s;
}
a#menu-share:hover > i{
animation: rotate-out 0.5s;
}
@keyframes bot-to-top {
0% {bottom:-40px}
50% {bottom:40px}
}
@keyframes scale-in {
from {transform: scale(0);opacity: 0;}
to {transform: scale(1);opacity: 1;}
}
@keyframes rotate-in {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
@keyframes rotate-out {
from {transform: rotate(360deg);}
to {transform: rotate(0deg);}
}
a#menu-share + ul {
visibility: hidden;
}
a#menu-share:focus + ul{
visibility: visible;
animation: scale-in 0.5s;
}
a#menu-share:focus {
display: none;
}
</style>
</head>
<body>
<a href="javascript:void(0);" class="float" id="menu-close">
<i class="fa fa-times my-float"></i>
</a>
<a href="javascript:void(0);" class="float" id="menu-share">
<i class="fa fa-share my-float"></i>
</a>
<ul>
<li><a href="#" id="menu-facebook">
<i class="fa fa-facebook my-float"></i>
</a></li>
<li><a href="#" id="menu-google-plus">
<i class="fa fa-google-plus my-float"></i>
</a></li>
<li><a href="#" id="menu-twitter">
<i class="fa fa-twitter my-float"></i>
</a></li>
</ul>
</body>
</html>
该代码仅在 Firefox 上运行良好。我使用了 :focus css 并且它只在 firefox 上运行良好。其他浏览器未使用 :focus 打开弹出窗口。
我也制作了 jsfiddle,它在那里工作得很好。 https://jsfiddle.net/wtrx3gc9/
有人可以分享提示或帮助我使用 :focus 在所有浏览器上显示弹出窗口。
在 Chrome 中,当您给它 display: none
时,元素失去焦点。
解决方案:以另一种方式隐藏它,例如通过给它 z-index: 100;
(或任何小于关闭按钮的 z-index 的值)。
@import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css');
*{padding:0;margin:0;}
body{
font-family:Verdana, Geneva, sans-serif;
background-color:#CCC;
font-size:12px;
}
.label-container{
position:fixed;
bottom:48px;
right:105px;
display:table;
visibility: hidden;
}
.label-text{
color:#FFF;
background:rgba(51,51,51,0.5);
display:table-cell;
vertical-align:middle;
padding:10px;
border-radius:3px;
}
.label-arrow{
display:table-cell;
vertical-align:middle;
color:#333;
opacity:0.5;
}
.float{
position:fixed;
width:60px;
height:60px;
bottom:40px;
right:40px;
background-color:#F33;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
z-index:1000;
}
ul{
position:fixed;
right:40px;
padding-bottom:20px;
bottom:80px;
z-index:100;
}
ul li{
list-style:none;
margin-bottom:10px;
}
ul li a{
background-color:#F33;
color:#FFF;
border-radius:50px;
text-align:center;
box-shadow: 2px 2px 3px #999;
width:60px;
height:60px;
display:block;
}
ul:hover{
visibility:visible!important;
opacity:1!important;
}
.my-float{
font-size:24px;
margin-top:18px;
}
a#menu-share i{
animation: rotate-in 0.5s;
}
a#menu-share:hover > i{
animation: rotate-out 0.5s;
}
@keyframes bot-to-top {
0% {bottom:-40px}
50% {bottom:40px}
}
@keyframes scale-in {
from {transform: scale(0);opacity: 0;}
to {transform: scale(1);opacity: 1;}
}
@keyframes rotate-in {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
@keyframes rotate-out {
from {transform: rotate(360deg);}
to {transform: rotate(0deg);}
}
a#menu-share + ul {
visibility: hidden;
}
a#menu-share:focus + ul{
visibility: visible;
animation: scale-in 0.5s;
}
a#menu-share:focus {
/* display: none;*/
z-index: 100;
}
<a href="javascript:void(0);" class="float" id="menu-close">
<i class="fa fa-times my-float"></i>
</a>
<a href="javascript:void(0);" class="float" id="menu-share">
<i class="fa fa-share my-float"></i>
</a>
<ul>
<li><a href="#" id="menu-facebook">
<i class="fa fa-facebook my-float"></i>
</a></li>
<li><a href="#" id="menu-google-plus">
<i class="fa fa-google-plus my-float"></i>
</a></li>
<li><a href="#" id="menu-twitter">
<i class="fa fa-twitter my-float"></i>
</a></li>
</ul>