如何使边距不会抵消我的网格

时间:2016-05-03 01:21:11

标签: javascript css

我目前正在制作一款游戏,在游戏中使用方块进行游戏。目前,我正在试图弄清楚如何制作它,以便盒子在显示时没有偏移。相反,我希望他们处于平等的网格中。我无法弄清楚如何摆脱这种恼人的偏移。我的代码如下:

JavaScript的:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js">  </script>
<body>
<div id = "square1" class = "gridsquare">
<div class = "gridsquarecontent" id = "square1content">
Welcome to Idle Grid! An exponentially complex idle displayed through stylish boxes! This cute little square is the one to get new squares. <button onclick = "$('#square2').show();document.getElementById('square1content').innerHTML =  'Nice! Use your new square to afford the next one!'" id = "btn-1">Get a new square</button>
</div>
</div>
<div id = "square2" class = "gridsquare">
<div class = "gridsquarecontent">
Git gud
</div>
</div>
</body>
<script>$("#square2").hide()</script>

CSS:

body{width:820px;height:820px;border-color:black;border-width:0px;border-style:solid;margin:5px;font-family:arial;font-size:14px;margin-top:0px}
.gridsquare{width:200px;height:200px;border-color:black;border-width:1px;border-style:solid;display:inline-block;overflow:none;background-color:white;margin-top:5px}
.gridsquarecontent{margin:10px;overflow:none}
button{background-color:white;border-color:Black;border-width:1px;display:block;margin-top:5px;transition: background-color,color 0.3s}
button:hover{outline:0;background-color:black;color:white}
button:focus{outline:0}

2 个答案:

答案 0 :(得分:0)

你有很多边距&gt; 0。将它们设置为零并仅增加定位所需的值。现在我觉得你有一个保证金的情况&#34;堆叠&#34;。Zero把你的&#34;堆栈&#34;首先从最重要的边距开始,然后根据需要添加更多边距。
请记住,如果紧密贴合,边距往往会推动对象。

答案 1 :(得分:0)

确保您有一个活动区域(带有它的持有者div以及指定宽度的自己的规则)并在该父元素下加载方块。然后在.gridsquare规则上添加float:left,方块将落在原位。