-2

我正在尝试为扫雷 Web 游戏制作基本的 HTML5/CSS3 框架。但由于某种原因,我无法让我的按钮移出它们的静态位置。我做错了什么?这是我的代码(注意:我使用的是 NetBeans 8.1 IDE)

HTML:

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>Minesweeper Web App</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="shortcut icon" href="http://old.no/icon/entertainment/mini-mine.gif" />
        <link rel="stylesheet" href="classes.css" type="text/css"/>
        <link rel="stylesheet" href="stylesheet.css" type="text/css"/>
    </head>
    <body>
        <div class="header">
        <h1>Minesweeper!!!!</h1>
        <p>Made by Desmond</p>
        </div>
        <div class="sub-header">
            <div class="img-box" id="left">
                <img src="#" id="smile" alt="this game is broken!"/>
            </div>
            <div class="img-box" id="right">
                <img src="#" id="flag" alt="This game is broken!"/>
            </div>
            <p id="score">Score: </p>
        </div>
        <div class="body">
            <div class="grid-box">
                <div class="button" id="5x5">
                    <p>Easy (5x5)</p>
                </div>
                <div class="button" id="8x8">
                    <p>Medium (8x8)</p>
                </div>
                <div class="button" id="10x10">
                    <p>Hard (10x10)</p>
                </div>
            </div>
        </div>
    </body>
</html>

CSS:`

.header {
width:100%;
height:20%;
border-bottom:2px solid #efefef;
border-radius:5px;
background:#80ffff;
text-align:center;
font-family:"Comic Sans MS", cursive;
}

.sub-header {
width:100%;
height:10%;
border-bottom:2px solid #efefef;
border-radius:5px;
background:#e5ffff;
}

.img-box {
display:inline-block;
position:relative;
width:50px;
height:50px;
background:radial-gradient(#cccccc 20%, #999999 80%);
border:2px solid #cccccc;
border-radius:2px;
align-content:center
}
.img-box img {
vertical-align:middle;
}
.button {
    position: relative;
    background-color: #efefef;
    height: 30px;
    width: 100px;
    border: 2px #999999 solid;
    border-radius:8px;
    font-family:"Modern No. 20";
    font-weight:bold;
    margin-left: 100px;
}
.button p {
    position: absolute;
    top: -8px;
}
.header p {
    text-shadow: 2px 2px gray;
    right: 1px;
}

.sub-header {
text-align:center;
margin-top:0px;
}

.body {
background:#d9d9d9;
height:1000px;
width:100%;
}

#8x8 {
left: 500px;
}

#10x10 {
left:1000px;
}

.grid-box {}
4

1 回答 1

0

您无法移动按钮,因为 div id 是数字。他们应该至少有一个字符。我改变了身份证,现在它的工作。 HTML

<div class="header">
  <h1>Minesweeper!!!!</h1>
  <p>Made by Desmond</p>
</div>
<div class="sub-header">
  <div class="img-box" id="left">
    <img src="#" id="smile" alt="this game is broken!" />
  </div>
  <div class="img-box" id="right">
    <img src="#" id="flag" alt="This game is broken!" />
  </div>
  <p id="score">Score: </p>
</div>
<div class="body">
  <div class="grid-box">
    <div class="button" id="5x5">
      <p>Easy (5x5)</p>
    </div>
    <div class="button" id="eight">
      <p>Medium (8x8)</p>
    </div>
    <div class="button" id="ten">
      <p>Hard (10x10)</p>
    </div>
  </div>
</div>

CSS:

.header {
  width: 100%;
  height: 20%;
  border-bottom: 2px solid #efefef;
  border-radius: 5px;
  background: #80ffff;
  text-align: center;
  font-family: "Comic Sans MS", cursive;
}

.sub-header {
  width: 100%;
  height: 10%;
  border-bottom: 2px solid #efefef;
  border-radius: 5px;
  background: #e5ffff;
}

.img-box {
  display: inline-block;
  position: relative;
  width: 50px;
  height: 50px;
  background: radial-gradient(#cccccc 20%, #999999 80%);
  border: 2px solid #cccccc;
  border-radius: 2px;
  align-content: center
}

.img-box img {
  vertical-align: middle;
}

.button {
  position: relative;
  background-color: #efefef;
  height: 30px;
  width: 100px;
  border: 2px #999999 solid;
  border-radius: 8px;
  font-family: "Modern No. 20";
  font-weight: bold;
  margin-left: 100px;
}

.button p {
  position: absolute;
  top: -8px;
}

.header p {
  text-shadow: 2px 2px gray;
  right: 1px;
}

.sub-header {
  text-align: center;
  margin-top: 0px;
}

.body {
  background: #d9d9d9;
  height: 1000px;
  width: 100%;
}

#eight {
  left: 200px;
}

#ten {
  left: 1000px;
}

.grid-box {}

这是解决方案的一个小提琴 。有关更多信息,请阅读此

于 2015-12-12T04:56:06.123 回答