好的,这里的技巧是使用额外的 HTML 标记来<div>
分别设置 children 和 parent 的样式。您可以根据需要调整尺寸,但如果您的数学运算正确,这应该是正确的(每个.day
和属性都需要是's 的.date
width
1/7 )。.container
width
这是更新的小提琴:http: //jsfiddle.net/NX2vM/10/
这是如何运作的?父级<div>
(.day
和.date
) 包含 width 属性。我们添加一个孩子,我们设置其高度和宽度将自动适应父级。我们将边框应用到这个子 div,所以边框是“inset”(100px 宽,包括边框)与 outset(100px + 1px 左边框 + 1px 右边框 = 102px)
HTML(注意重复的 div):
<div class = "container">
<div class = "day"><div>mon</div></div>
<div class = "day"><div>tue</div></div>
<div class = "day"><div>wed</div></div>
<div class = "day"><div>thu</div></div>
<div class = "day"><div>fri</div></div>
<div class = "day"><div>sat</div></div>
<div class = "day"><div>sun</div></div>
<div class = "option" id = "opp_1"></div>
<div class = "option" id = "opp_2"></div>
<div class = "option" id = "opp_3"></div>
<div class = "option" id = "opp_4"></div>
<div class = "option" id = "opp_5"></div>
<div class = "option" id = "opp_6"></div>
<div class = "date"><div>1</div></div>
<div class = "date"><div>2</div></div>
<div class = "date"><div>3</div></div>
<div class = "date"><div>4</div></div>
<div class = "date"><div>5</div></div>
<div class = "date"><div>6</div></div>
<div class = "date"><div>7</div></div>
<div class = "date"><div>8</div></div>
<div class = "date"><div>9</div></div>
<div class = "date"><div>10</div></div>
<div class = "date"><div>11</div></div>
<div class = "date"><div>12</div></div>
<div class = "date"><div>13</div></div>
<div class = "date"><div>14</div></div>
<div class = "date"><div>15</div></div>
<div class = "date"><div>16</div></div>
<div class = "date"><div>17</div></div>
<div class = "date"><div>18</div></div>
<div class = "date"><div>19</div></div>
<div class = "date"><div>20</div></div>
<div class = "date"><div>21</div></div>
<div class = "date"><div>22</div></div>
<div class = "date"><div>23</div></div>
<div class = "date"><div>24</div></div>
<div class = "date"><div>25</div></div>
<div class = "date"><div>26</div></div>
<div class = "date"><div>27</div></div>
<div class = "date"><div>28</div></div>
<div class = "date"><div>29</div></div>
<div class = "date"><div>30</div></div>
<div class = "date"><div>31</div></div>
</div>
CSS:
.container{
width: 700px;
border:1px solid black;
position:absolute;
}
.date{
width:100px;
float:left;
}
.date div {
border: 1px solid blue;
height:50px;
}
.day{
width:100px;
float:left;
background-color:grey;
}
.day div {
border: 1px solid grey;
height:20px;
}
.option{
width:100px;
height:50px;
float:left;
}