我有一个网页,但在不同的浏览器上看起来不同。甚至我给出的填充和边距的数量也很遥远,我们不要谈论 JS 的东西。我也在这里直播:
https
://iam-shivam.github.io/DrumPad/drumpad.html如何确保它们在所有浏览器上看起来都一样?某种方式来自动化这个或手动提示?
我什至尝试了一个无前缀的脚本,但它似乎没有任何好处。也许我用错了。这是链接:
http: //leaverou.github.io/prefixfree/
HTML 文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Virtual DrumPad</title>
<link rel="stylesheet" href="css\bootstrap.min.css">
<link rel="stylesheet" href="css\drumpad.css">
<link rel="prefetch" href="sounds\">
<script type="text/javascript" src="https://raw.githubusercontent.com/LeaVerou/prefixfree/gh-pages/plugins/prefixfree.jquery.js"></script>
</head>
<body>
<div class="container">
<div class="row middle">
<div class="header" style="">
<img src="images/logo.png" alt="Logo" width="300px" height="118px">
</div>
<div class="container col-xs-12 col-md-8 col-md-offset-2 buttonGroup">
<div class="row">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-10 col-md-offset-1 big">
<button data-key="65" class="drumpad">A<br><sub>CLAP</sub></</button>
<button data-key="83" class="drumpad">S<br><sub>HIHAT</sub></</button>
<button data-key="68" class="drumpad">D<br><sub>KICK</sub></</button>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-10 col-md-offset-1 big">
<button data-key="70" class="drumpad">F<br><sub>OPENHAT</sub></</button>
<button data-key="71" class="drumpad">G<br><sub>BOOM</sub></</button>
<button data-key="72" class="drumpad">H<br><sub>RIDE</sub></button>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-10 col-md-offset-1 big">
<button data-key="74" class="drumpad">J<br><sub>SNARE</sub></</button>
<button data-key="75" class="drumpad">K<br><sub>TOM</sub></</button>
<button data-key="76" class="drumpad">L<br><sub>TINK</sub></button>
</div>
</div>
</div>
</div>
</div>
<script src="scripts\jquery-3.2.1.min.js"></script>
<script src="scripts\bootstrap.min.js"></script>
<script>
function playIt(e){
var keys = document.querySelector('[data-key="'+e.keyCode+'"]');
if(keys == null)return;
mainStuff(keys);
}
function mainStuff(keys){
keys.classList.add('playing');
var sname = keys.querySelector('sub').innerHTML.toLowerCase();
var audio = new Audio("sounds\\"+sname+".wav");
audio.play();
keys.addEventListener('transitionend',function(){
keys.classList.remove('playing');
});
}
document.addEventListener('keydown',playIt);
var all = document.querySelectorAll('.drumpad');
all.forEach(key => key.addEventListener('click', function(){
mainStuff(this);
}));
</script>
</body>
</html>
CSS 文件:
:root {
--bcolor: black;
}
body {
margin: 0;
padding: 0;
background-color: #000000;
}
.middle {
background-image: url('../images/background.png');
background-repeat: no-repeat;
background-size: cover;
-moz-background-size: cover;
-webkit-background-size: cover;
height: 100vh;
border-left: 4px solid var(--bcolor);
border-right: 4px solid var(--bcolor);
}
.header {
text-align: center;
color: white;
}
.drumpad {
padding: 8%;
float: left;
margin: 0.5%;
background-color: #020202;
background-color: rgba(2, 2, 2, 0.6);
color: white;
border: 2px solid white;
box-shadow: 1px 1px 3px 0 rgba(0, 0, 0, 0.2);
-moz-box-shadow: 1px 1px 3px 0 rgba(0, 0, 0, 0.2);
-webkit-box-shadow: 1px 1px 3px 0 rgba(0, 0, 0, 0.2);
font-size: 1.7rem;
transition: all 0.07s;
-moz-transition: all 0.07s;
-ms-transition: all 0.07s;
-o-transition: all 0.07s;
-webkit-transition: all 0.07s;
font-weight: bold;
width: 150px;
text-align: center;
}
.playing ,
.drumpad:active {
background-color: #020202;
background-color: rgba(2, 2, 2, 0.8);
border: 2px solid #1A0000;
border: 2px solid rgba(26, 0, 0, 0);
transform: scale(1.05);
-moz-transform: scale(1.05);
-ms-transform: scale(1.05);
-o-transform: scale(1.05);
-webkit-transform: scale(1.05);
}
.big {
display: flex;
justify-content: center;
}
.buttonGroup {
margin-top: 3%;
}
@media screen and (orientation:portrait) {
.buttonGroup button{
padding: 10%;
}
.buttonGroup{
margin-top: 10%;
}
.drumpad{
margin: 1%;
width: 120px;
}
}