我想弄清楚如何集中(垂直和水平)我的innerHTML
記住內容的長度。這是我的HTML和CSS。Codeacademy的岩石,紙,剪刀遊戲
<body>
<div class="container">
<p id="demo"></p>
<script>
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} document.getElementById("demo").innerHTML = "Computer: " + computerChoice;
var compare = function(choice1, choice2) {
if(choice1 === choice2) {
document.getElementById("demo").innerHTML = "The result is a tie!";
} else if (choice1 === "rock") {
if (choice2 === "scissors") {
document.getElementById("demo").innerHTML = "Congratulatioins, you win!";
} else {
document.getElementById("dmeo").innerHTML = "Sorry, the computer shows paper. You lost!";
}
} else if (choice1 === "paper") {
if (choice2 === "rock") {
document.getElementById("demo").innerHTML = "Congratulatioins, you win!";
} else {
document.getElementById("demo").innerHTML = "Sorry, the computer shows scissors. You lost!";
}
} else if (choice1 === "scissors") {
if (choice2 === "paper") {
document.getElementById("demo").innerHTML = "Congratulatioins, you win!";
} else {
document.getElementById("demo").innerHTML = "Sorry, the computer shows rock. You lost!";
}
}
}
compare (userChoice, computerChoice);
</script>
.container {
width: 50%;
margin: 0 auto;
padding: 10px;
}
body {
background-image: url(images/bg-img.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
margin: 0;
}
#demo {
font-family: Impact;
font-size: 40px;
color: #cddc39;
text-shadow: 2px 4px 3px rgba(106, 209, 25, 0.62);
}
是網站是在CSS定心的東西非常有用:http://howtocenterincss.com/ –