这是相关的HTML:
<div class="row">
<div class="arrow box">◄</div>Month Year<div class="dayMonth box"></div>►<div class="arrow box"></div>
</div>
这是上述 HTML 所在的 .html 文件链接到的 css:
*
{
margin: 0;
padding: 0;
}
body
{
font-family: "Times New Roman";
font-size: 12pt;
}
.dayMonth
{
width: 80%;
}
.arrow
{
width: 10%;
}
.row
{
width: 58em;
background-color: gray;
margin-right: auto;
margin-left: auto;
}
.box
{
float: left;
text-align: center;
}
这是输出:
“行”在浏览器右侧居中,但里面的东西(两个箭头和月份)没有做我想要的。
我认为这应该做的是,因为有两个箭头,它们的宽度都被发送到 10%,然后 dayMonth 宽度是 80%,所有 div 都应该占据整个“行”(因为它们总和为 100 %) 并且文本 "Month Year" 应该在 "row" 中居中,因为 .dayMonth css 类说它应该在其 div 中居中并且因为它的 div 应该是 "row" 的中心 80%。显然,这并没有发生。
我不想要一个不同的解决方案(本身)我想知道为什么我写的代码没有表达我想要表达的想法,没有按照我想要的方式工作。
我想我一定是误解了 %'s 如何控制宽度。http://www.w3schools.com/css/pr_dim_width.asp说 % 的“以包含块的百分比定义宽度”,看起来 % 应该做我打算让他们做的事情,所以我米彻底糊涂了。
我哪里出错了?