【发布时间】:2017-01-24 16:33:03
【问题描述】:
晚上好。我需要有关 CSS 的帮助。我知道这个问题已经解决了很多次,但由于某种原因,它似乎不适用于我的程序。 此脚本用于设计 8x8 板,板上的单元格是 8 种不同颜色之一。所以我打算做的是定义一个以黑色背景为中心的 div。在这个 div 中将是我的董事会。由于纵向和横向需要 8 个单元格,我将按钮的宽度和高度各自的属性设置为 12.5%,即 (100/8)% 我没有指定任何显式填充,但仍然所有按钮都与一些相关联(主要在右边)。
html,
body {
height: 100%;
width: 100%;
}
button::-moz-focus-inner
/*Recommended fix. But not working*/
{
border: 0;
padding: 0;
}
.c1 {
/*For coloring the buttons*/
background-color: #cdaf95;
}
/*Here is the code for classes c2 -c7*/
.c8 {
background-color: #5e2612;
}
.col1 {
/*For defining the size of the buttons.*/
width: 12.5%;
height: 12.5%;
padding: 0;
border: 0;
}
/*Here is code for classes col2-col7*/
.col8 {
width: 12.5%;
height: 12.5%;
padding: 0;
border: 0;
}
/*Board is the id of the division*/
#board {
height: 50%;
width: 50%;
top: 0;
bottom: 0;
left: 0;
right: 0;
max-width: 400px;
max-height: 400px;
position: absolute;
margin: auto;
background-color: white;
}
<body bgcolor="black">
<style>
</style>
<div id="board">
<button class="col1 c1"></button>
<button class="col2 c1"></button>
<button class="col3 c1"></button>
<button class="col4 c1"></button>
<button class="col5 c1"></button>
<button class="col6 c1"></button>
<button class="col7 c1"></button>
<button class="col8 c1"></button>
<button class="col1 c2"></button>
<button class="col2 c2"></button>
<!--And so on upto c8. Thats a total of 64 buttons forming an 8x8 board-->
<button class="col7 c8"></button>
<button class="col8 c8"></button>
</div>
</body>
我们将不胜感激以这种方式提供的任何帮助。提前谢谢你。
【问题讨论】:
-
按钮是内联元素吗?可能需要让它们阻挡或移除它们周围的空白区域
-
分享一个工作示例。您分享的代码很好,没有填充。
标签: html css firefox button padding