我正在尝试将压光机放置在透明的div容器中,但是我遇到了一些问题,我希望每个压光机盒在透明盒中形成一个宽度占100%的行。所以基本上现在页面看起来像这样:
screenshot

您可能会注意到,如果您在容器中单击“单击图像文本”,则该框宽于其下的行。

这是日历的CSS代码:基本上,所有与.transbox相关的东西都与透明框有关。日历日是.weekdayssttart和工作日类。其余的类别是带有编号的日历日。因此,由于每周有7天,我只是想我不得不将100/7除以14.2857142857,然后将每个框类型设置为该宽度百分比。但这是我得到的结果:screenshot2。我显然注意到的是,该行很小以容纳日历框,是否有人想解决此问题?对不起,我的英语不好。



.transbox {
    background: #fff;
    padding: 2%;
    width: 70%;
    margin-left: 15%;
    margin-bottom: 1%;
    position: relative;
    background-color:rgba(255,255,255,.9);
    border-radius: 5px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,.9);
    overflow: auto;
}

.transbox p {
    color: darkslategray;
    margin-bottom: 2%;
    font-size:13px;
}

.transbox img {
    width:100%;
    height: 100%;
}

.weekdaysstart {
    width: 14%;
    height: 20px;
    background-color:floralwhite;
    border: 1px solid darkslategrey;
    text-align:center;
    float: left;
}

.weekdays {
    width: 14%;
    height: 20px;
    background-color:floralwhite;
    border: 1px solid darkslategrey;
    text-align:center;
    float: left;
}

.hint {
    width: 99%;
    height: 20px;
    background-color:floralwhite;
    border: 1px solid darkslategrey;
    text-align:center;
    padding-top: 5px;

}

.one {
  background-color: floralwhite;
  width: 14%;
  height: 100px;
  float: left;
  border: 1px solid darkslategrey;
  color: darkslategrey;

}

.nextrow {
  background-color: floralwhite;
  width: 14%;
  height: 100px;
  float: left;
  clear:left;
  border: 1px solid darkslategrey;
  color: darkslategrey;


}

.nextmonth {
  background-color: floralwhite;
  width: 14%;
  height: 100px;
  float: left;
  border: 1px solid darkslategrey;
  color: darkslategrey;
}

.lastrow {
  width: 14%;
  height: 100px;
  float: left;
  border: 1px solid darkslategrey;
  color: darkslategrey;
  background-color: floralwhite;
  margin-bottom:2%;
}

.pancakes {
    width: 14%;
    height: 100px;
    float:left;
    background: url(images/pancakes.jpeg);
    background-size: cover;
    border: 1px solid darkslategrey;
}

.meatballs {
    width: 14%;
    height: 100px;
    float:left;
    border: 1px solid darkslategrey;
    background: url(images/kotbulls.jpg);
    background-size: cover;
}

<!DOCTYPE html>
<html>
<head>
	<title>Tasty recipes</title>
	<link href="reset.css" rel="stylesheet" type="text/css">
	<link href="stylesheet.css" rel="stylesheet" type="text/css">
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body>
	<ul>
		<li><a href="index.html">HOME</a></li>
		<li><a href="recipes.html">RECIPES</a></li>
		<li><a href="calendar.html">CALENDAR</a></li>
		<li class="tastyrecipes">Tasty Recipes</li>
	</ul>
	<h1>Calendar</h1>
	<h3>November 2017</h3>
    <div class = "transbox">
	<div class="hint">
		<p>Click on the image of a dish to go to its recipe-page.</p>
	</div>
	<div class="weekdaysstart">
		<p>Monday</p>
	</div>
	<div class="weekdays">
		<p>Tuesday</p>
	</div>
	<div class="weekdays">
		<p>Wednesday</p>
	</div>
	<div class="weekdays">
		<p>Thursday</p>
	</div>
	<div class="weekdays">
		<p>Friday</p>
	</div>
	<div class="weekdays">
		<p>Saturday</p>
	</div>
	<div class="weekdays">
		<p>Sunday</p>
	</div>
	<div class="nextrow">
		<p>30</p>
	</div>
	<div class="one">
		<p>31</p>
	</div>
	<div class="one">
		<p>1</p>
	</div>
	<div class="one">
		<p>2</p>
	</div>
	<div class="one">
		<p>3</p>
	</div>
	<div class="one">
		<p>4</p>
	</div>
	<div class="one">
		<p>5</p>
	</div>
	<div class="nextrow">
		<p>6</p>
	</div>
    <a href="meatballs.html">
	<div class="meatballs">
		<p>7</p>
	</div>
    </a>
	<div class="one">
		<p>8</p>
	</div>
	<div class="one">
		<p>9</p>
	</div>
	<div class="one">
		<p>10</p>
	</div>
	<div class="one">
		<p>11</p>
	</div>
	<div class="one">
		<p>12</p>
	</div>
	<div class="nextrow">
		<p>13</p>
	</div>
	<div class="one">
		<p>14</p>
	</div>
	<div class="one">
		<p>15</p>
	</div>
	<div class="one">
		<p>16</p>
	</div>
	<div class="one">
		<p>17</p>
	</div>
	<div class="one">
		<p>18</p>
	</div>
	<div class="one">
		<p>19</p>
	</div>
	<div class="nextrow">
		<p>20</p>
	</div>
	<div class="one">
		<p>21</p>
	</div>
	<div class="one">
		<p>22</p>
	</div>
	<div class="one">
		<p>23</p>
	</div>
	<div class="one">
		<p>24</p>
	</div>
    <a href="pancakes.html">
	<div class="pancakes">
		<p>25</p>
	</div>
    </a>
	<div class="one">
		<p>26</p>
	</div>
	<div class="nextrow">
		<p>27</p>
	</div>
	<div class="lastrow">
		<p>28</p>
	</div>
	<div class="lastrow">
		<p>29</p>
	</div>
	<div class="lastrow">
		<p>30</p>
	</div>
	<div class="nextmonth">
		<p>1</p>
	</div>
	<div class="nextmonth">
		<p>2</p>
	</div>
	<div class="nextmonth">
		<p>3</p>
	</div>
    </div>
</body>
</html>

最佳答案

就像Matthew JohnSon所说的,您可以使用flexbox做到这一点。我不太确定,但是我相信calc()函数会适合它。

.transbox {
    width: 100%;
    display: flex;
    flex-flow: row nowrap;
    justify-content: flex-start;
}

.weekdaysstart, .weekdays {
    width: calc(100% / 7);
}


编辑

我将类的名称更改为您的html类的名称。

关于css - 在div容器中将float元素连续放置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47143579/

10-09 23:26